[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:
Silviu Popa
2021-01-19 15:57:20 +02:00
committed by GitHub
parent 885792ba01
commit 98705109e1
5 changed files with 85 additions and 22 deletions

View File

@@ -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();

View File

@@ -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.