X-Git-Url: https://gerrit.o-ran-sc.org/r/gitweb?a=blobdiff_plain;f=webapp-frontend%2Fsrc%2Fapp%2Fpolicy%2Fno-type-policy-editor%2Fno-type-policy-editor.component.ts;h=877e0e37e7115fe4a1fd756895bdfb7efa0fdcc8;hb=e0f0ae59f6f1958617c927bdfbec63e037efed97;hp=d231b00bc057de49f809320ea6de33cd8ffa3a90;hpb=a2a4491f5e44b5979f0d84a3065bcf76f3b01b93;p=portal%2Fnonrtric-controlpanel.git diff --git a/webapp-frontend/src/app/policy/no-type-policy-editor/no-type-policy-editor.component.ts b/webapp-frontend/src/app/policy/no-type-policy-editor/no-type-policy-editor.component.ts index d231b00..877e0e3 100644 --- a/webapp-frontend/src/app/policy/no-type-policy-editor/no-type-policy-editor.component.ts +++ b/webapp-frontend/src/app/policy/no-type-policy-editor/no-type-policy-editor.component.ts @@ -54,6 +54,7 @@ export class NoTypePolicyEditorComponent implements OnInit { this.jsonValidator(), ]) ); + if (!this.policyJson) this.policyJson = "{}"; } get policyJsonTextArea(): AbstractControl { @@ -63,9 +64,9 @@ export class NoTypePolicyEditorComponent implements OnInit { } formatJsonInput(): void { - this.policyJson = formatJsonString( - JSON.parse(this.policyJsonTextArea.value) - ); + let jsonBefore: string = this.policyJsonTextArea.value; + let jsonAfter = formatJsonString(JSON.parse(jsonBefore)); + this.policyJsonTextArea.setValue(jsonAfter); } jsonValidator(): ValidatorFn { @@ -85,16 +86,14 @@ export class NoTypePolicyEditorComponent implements OnInit { } isJsonValid(json: string): boolean { + let valid = false as boolean; try { if (json != null) { JSON.parse(json); - return true; - } else { - return false; + valid = true; } - } catch (jsonError) { - return false; - } + } catch (jsonError) {} + return valid; } }