diff --git a/src/lib/src/framework-library/material-design-framework/material-checkboxes.component.ts b/src/lib/src/framework-library/material-design-framework/material-checkboxes.component.ts index aa995ba1..1e0ae3d1 100755 --- a/src/lib/src/framework-library/material-design-framework/material-checkboxes.component.ts +++ b/src/lib/src/framework-library/material-design-framework/material-checkboxes.component.ts @@ -97,7 +97,10 @@ export class MaterialCheckboxesComponent implements OnInit { updateValue() { this.options.showErrors = true; if (this.boundControl) { - this.jsf.updateArrayCheckboxList(this, this.checkboxList); + this.jsf.updateValue(this, this.checkboxList + .filter(checkboxItem => checkboxItem.checked) + .map(checkboxItem => checkboxItem.value) + ); } } diff --git a/src/lib/src/json-schema-form.service.ts b/src/lib/src/json-schema-form.service.ts index 372f51c2..810ed08b 100755 --- a/src/lib/src/json-schema-form.service.ts +++ b/src/lib/src/json-schema-form.service.ts @@ -499,8 +499,12 @@ export class JsonSchemaFormService { // Set value of current control ctx.controlValue = value; if (ctx.boundControl) { - ctx.formControl.setValue(value); - ctx.formControl.markAsDirty(); + if (isArray(value)) { + this.updateArray(ctx, value); + } else { + ctx.formControl.setValue(value); + ctx.formControl.markAsDirty(); + } } ctx.layoutNode.value = value; @@ -516,7 +520,7 @@ export class JsonSchemaFormService { } } - updateArrayCheckboxList(ctx: any, checkboxList: TitleMapItem[]): void { + protected updateArray(ctx: any, items: any[]): void { const formArray = this.getFormControl(ctx); // Remove all existing items @@ -526,12 +530,10 @@ export class JsonSchemaFormService { const refPointer = removeRecursiveReferences( ctx.layoutNode.dataPointer + '/-', this.dataRecursiveRefMap, this.arrayMap ); - for (const checkboxItem of checkboxList) { - if (checkboxItem.checked) { - const newFormControl = buildFormGroup(this.templateRefLibrary[refPointer]); - newFormControl.setValue(checkboxItem.value); - formArray.push(newFormControl); - } + for (const item of items) { + const newFormControl = buildFormGroup(this.templateRefLibrary[refPointer]); + newFormControl.setValue(item); + formArray.push(newFormControl); } formArray.markAsDirty(); } diff --git a/src/lib/src/shared/json.validators.ts b/src/lib/src/shared/json.validators.ts index 34ebb8e0..62cddfc6 100755 --- a/src/lib/src/shared/json.validators.ts +++ b/src/lib/src/shared/json.validators.ts @@ -186,18 +186,17 @@ export class JsonValidators { return (control: AbstractControl, invert = false): ValidationErrors|null => { if (isEmpty(control.value)) { return null; } const currentValue: any = control.value; - const isEqual = (enumValue, inputValue) => - enumValue === inputValue || - (isNumber(enumValue) && +inputValue === +enumValue) || - (isBoolean(enumValue, 'strict') && - toJavaScriptType(inputValue, 'boolean') === enumValue) || - (enumValue === null && !hasValue(inputValue)) || - _.isEqual(enumValue, inputValue); - const isValid = isArray(currentValue) ? - currentValue.every(inputValue => allowedValues.some(enumValue => - isEqual(enumValue, inputValue) - )) : - allowedValues.some(enumValue => isEqual(enumValue, currentValue)); + const areEqual = (enumValue, inputValue) => + enumValue === inputValue + || (isNumber(enumValue) && +inputValue === +enumValue) + || (isBoolean(enumValue, 'strict') && toJavaScriptType(inputValue, 'boolean') === enumValue) + || (enumValue === null && !hasValue(inputValue)) + || _.isEqual(enumValue, inputValue); + const isValid = isArray(currentValue) + ? currentValue.every(inputValue => allowedValues.some(enumValue => + areEqual(enumValue, inputValue) + )) + : allowedValues.some(enumValue => areEqual(enumValue, currentValue)); return xor(isValid, invert) ? null : { 'enum': { allowedValues, currentValue } }; }; diff --git a/src/lib/src/widget-library/checkboxes.component.ts b/src/lib/src/widget-library/checkboxes.component.ts index cc3069db..9499cab3 100755 --- a/src/lib/src/widget-library/checkboxes.component.ts +++ b/src/lib/src/widget-library/checkboxes.component.ts @@ -97,7 +97,10 @@ export class CheckboxesComponent implements OnInit { } } if (this.boundControl) { - this.jsf.updateArrayCheckboxList(this, this.checkboxList); + this.jsf.updateValue(this, this.checkboxList + .filter(checkboxItem => checkboxItem.checked) + .map(checkboxItem => checkboxItem.value) + ); } } }