Browse Source

Mini fix for json field.

pull/624/head
Sebastian 6 years ago
parent
commit
648b48aa0d
  1. 24
      frontend/app/framework/angular/forms/editors/code-editor.component.ts
  2. 2
      frontend/app/shared/state/contents.forms.ts
  3. 2
      frontend/app/shared/state/contents.forms.visitors.ts

24
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() {

2
frontend/app/shared/state/contents.forms.ts

@ -310,7 +310,7 @@ export class FieldValueForm extends AbstractContentForm<RootFieldDto, FormContro
validators.push(remoteValidator);
}
return new FormControl(value, { validators });
return new FormControl({ value, disabled: false }, { validators });
}
}

2
frontend/app/shared/state/contents.forms.visitors.ts

@ -382,7 +382,7 @@ export class FieldDefaultValue implements FieldPropertiesVisitor<any> {
}
public visitJson(_: JsonFieldPropertiesDto): any {
return null;
return undefined;
}
public visitNumber(properties: NumberFieldPropertiesDto): any {

Loading…
Cancel
Save