Commit 61d96b94f23fb52bdd3e6a25aef3def55114eede

Authored by Igor Kulikov
Committed by GitHub
2 parents b6aba1c4 82668c9d

Merge pull request #3061 from thingsboard/json_dialog_fix

fix buf Json edit
@@ -194,19 +194,19 @@ export class JsonObjectEditComponent implements OnInit, ControlValueAccessor, Va @@ -194,19 +194,19 @@ export class JsonObjectEditComponent implements OnInit, ControlValueAccessor, Va
194 } 194 }
195 195
196 beautifyJSON() { 196 beautifyJSON() {
197 - const res = JSON.stringify(this.modelValue, null, 2);  
198 - if (this.jsonEditor) { 197 + if (this.jsonEditor && this.objectValid) {
  198 + const res = JSON.stringify(this.modelValue, null, 2);
199 this.jsonEditor.setValue(res ? res : '', -1); 199 this.jsonEditor.setValue(res ? res : '', -1);
  200 + this.updateView();
200 } 201 }
201 - this.updateView();  
202 } 202 }
203 203
204 minifyJSON() { 204 minifyJSON() {
205 - const res = JSON.stringify(this.modelValue);  
206 - if (this.jsonEditor) { 205 + if (this.jsonEditor && this.objectValid) {
  206 + const res = JSON.stringify(this.modelValue);
207 this.jsonEditor.setValue(res ? res : '', -1); 207 this.jsonEditor.setValue(res ? res : '', -1);
  208 + this.updateView();
208 } 209 }
209 - this.updateView();  
210 } 210 }
211 211
212 writeValue(value: any): void { 212 writeValue(value: any): void {
@@ -254,6 +254,7 @@ export class JsonObjectEditComponent implements OnInit, ControlValueAccessor, Va @@ -254,6 +254,7 @@ export class JsonObjectEditComponent implements OnInit, ControlValueAccessor, Va
254 this.objectValid = !this.required; 254 this.objectValid = !this.required;
255 this.validationError = this.required ? 'Json object is required.' : ''; 255 this.validationError = this.required ? 'Json object is required.' : '';
256 } 256 }
  257 + this.modelValue = data;
257 this.propagateChange(data); 258 this.propagateChange(data);
258 } 259 }
259 } 260 }