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 {