mirror of
https://github.com/Alfresco/alfresco-ng2-components.git
synced 2025-07-24 17:32:15 +00:00
[MNT-22051] - Fix form field mapping when value is zero (#6517)
* [MNT-22051] - Fix form field mapping when value is zero * PR changes * add validation for null
This commit is contained in:
@@ -77,6 +77,14 @@ describe('FormModel', () => {
|
||||
expect(form.readOnly).toBeTruthy();
|
||||
});
|
||||
|
||||
it('should set form values when variable value is 0', () => {
|
||||
const variables = {
|
||||
pfx_property_one: 0
|
||||
};
|
||||
const form = new FormModel(fakeMetadataForm, variables, true);
|
||||
expect(form.getFormFields()[0].fields[1][0].value).toEqual(0);
|
||||
});
|
||||
|
||||
it('should check tabs', () => {
|
||||
const form = new FormModel();
|
||||
|
||||
|
@@ -234,13 +234,17 @@ export class FormModel {
|
||||
for (const field of this.getFormFields()) {
|
||||
const variableId = `variables.${field.name}`;
|
||||
|
||||
if (formValues[variableId] || formValues[field.id]) {
|
||||
if (this.isDefined(formValues[variableId]) || this.isDefined(formValues[field.id])) {
|
||||
field.json.value = formValues[variableId] || formValues[field.id];
|
||||
field.value = field.parseValue(field.json);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private isDefined(value: string): boolean {
|
||||
return value !== undefined && value !== null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a form variable that matches the identifier.
|
||||
* @param identifier The `name` or `id` value.
|
||||
|
Reference in New Issue
Block a user