mirror of
https://github.com/Alfresco/alfresco-ng2-components.git
synced 2025-07-24 17:32:15 +00:00
[AAE-7010] - Fix nested linked dropdowns are not reset (#7463)
* [AAE-7010] - Fix nested linked dropdowns are not reset * Rebase * Reset rest in case value is not part of the options * Update failing unit test due to form field changes
This commit is contained in:
@@ -531,7 +531,7 @@ describe('FormFieldModel', () => {
|
||||
expect(field.value).toBe(false);
|
||||
});
|
||||
|
||||
it('should update form with empty dropdown value', () => {
|
||||
it('should delete empty dropdown value from the form values', () => {
|
||||
const form = new FormModel();
|
||||
const field = new FormFieldModel(form, {
|
||||
id: 'dropdown-1',
|
||||
@@ -539,10 +539,10 @@ describe('FormFieldModel', () => {
|
||||
});
|
||||
|
||||
field.value = 'empty';
|
||||
expect(form.values['dropdown-1']).toEqual({});
|
||||
expect(form.values['dropdown-1']).toBe(undefined);
|
||||
|
||||
field.value = '';
|
||||
expect(form.values['dropdown-1']).toEqual({});
|
||||
expect(form.values['dropdown-1']).toBe(undefined);
|
||||
});
|
||||
|
||||
it('should update form with dropdown value', () => {
|
||||
|
@@ -293,17 +293,14 @@ export class FormFieldModel extends FormWidgetModel {
|
||||
if (json.type === FormFieldTypes.DROPDOWN) {
|
||||
|
||||
if (json.options) {
|
||||
const options = <FormFieldOption[]> json.options || [];
|
||||
if (options.length > 0) {
|
||||
if (json.hasEmptyValue) {
|
||||
const emptyOption = json.options[0];
|
||||
if (value === '' || value === emptyOption.id || value === emptyOption.name) {
|
||||
value = emptyOption.id;
|
||||
}
|
||||
} else {
|
||||
if (value?.id && value?.name) {
|
||||
value = value.id;
|
||||
}
|
||||
if (json.hasEmptyValue) {
|
||||
const emptyOption = json.options[0];
|
||||
if (value === '' || value === emptyOption.id || value === emptyOption.name) {
|
||||
value = emptyOption.id;
|
||||
}
|
||||
} else {
|
||||
if (value?.id && value?.name) {
|
||||
value = value.id;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -371,7 +368,7 @@ export class FormFieldModel extends FormWidgetModel {
|
||||
|
||||
if (typeof this.value === 'string') {
|
||||
if (this.value === 'empty' || this.value === '') {
|
||||
this.form.values[this.id] = {};
|
||||
delete this.form.values[this.id];
|
||||
break;
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user