From 648b48aa0d385daac487882ab2e80c325435886d Mon Sep 17 00:00:00 2001 From: Sebastian Date: Mon, 18 Jan 2021 16:55:44 +0100 Subject: [PATCH] Mini fix for json field. --- .../forms/editors/code-editor.component.ts | 24 +++++++++++-------- frontend/app/shared/state/contents.forms.ts | 2 +- .../shared/state/contents.forms.visitors.ts | 2 +- 3 files changed, 16 insertions(+), 12 deletions(-) diff --git a/frontend/app/framework/angular/forms/editors/code-editor.component.ts b/frontend/app/framework/angular/forms/editors/code-editor.component.ts index 121f210e2..386769882 100644 --- a/frontend/app/framework/angular/forms/editors/code-editor.component.ts +++ b/frontend/app/framework/angular/forms/editors/code-editor.component.ts @@ -59,10 +59,14 @@ export class CodeEditorComponent extends StatefulControlComponent<{}, string> im public writeValue(obj: string) { if (this.valueMode === 'Json') { - try { - this.value = JSON.stringify(obj, undefined, 4); - } catch (e) { + if (obj === null) { this.value = ''; + } else { + try { + this.value = JSON.stringify(obj, undefined, 4); + } catch (e) { + this.value = ''; + } } } else if (Types.isString(obj)) { this.value = obj; @@ -134,30 +138,30 @@ export class CodeEditorComponent extends StatefulControlComponent<{}, string> im } private changeValue() { - let newValue = this.aceEditor.getValue(); - let newValueOut = newValue; + let newValueText = this.aceEditor.getValue(); + let newValueOut = newValueText; if (this.valueMode === 'Json') { const isValid = this.aceEditor.getSession().getAnnotations().length === 0; if (isValid) { try { - newValueOut = JSON.parse(newValue); + newValueOut = JSON.parse(newValueText); } catch (e) { newValueOut = null; - newValue = ''; + newValueText = ''; } } else { newValueOut = null; - newValue = ''; + newValueText = ''; } } - if (this.value !== newValue) { + if (this.value !== newValueText) { this.callChange(newValueOut); } - this.value = newValue; + this.value = newValueText; } private setMode() { diff --git a/frontend/app/shared/state/contents.forms.ts b/frontend/app/shared/state/contents.forms.ts index ed534bb32..e7c6da015 100644 --- a/frontend/app/shared/state/contents.forms.ts +++ b/frontend/app/shared/state/contents.forms.ts @@ -310,7 +310,7 @@ export class FieldValueForm extends AbstractContentForm { } public visitJson(_: JsonFieldPropertiesDto): any { - return null; + return undefined; } public visitNumber(properties: NumberFieldPropertiesDto): any {