From f88ff10f30b72748bc63521c104200d2c324b56b Mon Sep 17 00:00:00 2001 From: Kasia Biernat <1268696+kathrine0@users.noreply.github.com> Date: Wed, 7 Aug 2024 15:21:41 +0200 Subject: [PATCH] AAE-23521 Fix improve dropdown reactive form (#10040) * AAE-23521 Fix improve dropdown reactive form * AAE-23521 Update process services dropdown * AAE-23521 pr suggestions * AAE-23521 move tests * AAE-23521 fixes --- .../widgets/core/form-field-types.ts | 2 +- .../widgets/core/form-field-validator.spec.ts | 45 --- .../widgets/core/form-field-validator.ts | 17 - .../widgets/error/error.component.scss | 1 + .../dropdown/dropdown-cloud.widget.html | 71 ++-- .../dropdown/dropdown-cloud.widget.scss | 6 + .../dropdown/dropdown-cloud.widget.spec.ts | 70 +++- .../widgets/dropdown/dropdown-cloud.widget.ts | 338 ++++++++++-------- .../src/lib/form/form-cloud.module.ts | 3 - .../src/lib/form/form.component.ts | 16 +- .../widgets/dropdown/dropdown.widget.html | 25 +- .../widgets/dropdown/dropdown.widget.spec.ts | 44 ++- .../form/widgets/dropdown/dropdown.widget.ts | 139 +++++-- 13 files changed, 456 insertions(+), 321 deletions(-) diff --git a/lib/core/src/lib/form/components/widgets/core/form-field-types.ts b/lib/core/src/lib/form/components/widgets/core/form-field-types.ts index f62cfd6ffea..3bda51016de 100644 --- a/lib/core/src/lib/form/components/widgets/core/form-field-types.ts +++ b/lib/core/src/lib/form/components/widgets/core/form-field-types.ts @@ -54,7 +54,7 @@ export class FormFieldTypes { static VALIDATABLE_TYPES: string[] = [FormFieldTypes.DISPLAY_EXTERNAL_PROPERTY]; - static REACTIVE_TYPES: string[] = [FormFieldTypes.DATE, FormFieldTypes.DATETIME]; + static REACTIVE_TYPES: string[] = [FormFieldTypes.DATE, FormFieldTypes.DATETIME, FormFieldTypes.DROPDOWN]; static CONSTANT_VALUE_TYPES: string[] = [FormFieldTypes.DISPLAY_EXTERNAL_PROPERTY]; diff --git a/lib/core/src/lib/form/components/widgets/core/form-field-validator.spec.ts b/lib/core/src/lib/form/components/widgets/core/form-field-validator.spec.ts index 48513ffdc90..1de609d2d3d 100644 --- a/lib/core/src/lib/form/components/widgets/core/form-field-validator.spec.ts +++ b/lib/core/src/lib/form/components/widgets/core/form-field-validator.spec.ts @@ -59,51 +59,6 @@ describe('FormFieldValidator', () => { expect(validator.validate(field)).toBe(true); }); - it('should fail (display error) for multiple type dropdown with zero selection', () => { - const field = new FormFieldModel(new FormModel(), { - type: FormFieldTypes.DROPDOWN, - value: [{ id: 'id_cat', name: 'Cat' }], - required: true, - selectionType: 'multiple', - hasEmptyValue: false, - options: [ - { id: 'id_cat', name: 'Cat' }, - { id: 'id_dog', name: 'Dog' } - ] - }); - - const validateBeforeUnselect = validator.validate(field); - field.value = []; - const validateAfterUnselect = validator.validate(field); - - expect(validateBeforeUnselect).toBe(true); - expect(validateAfterUnselect).toBe(false); - }); - - it('should fail (display error) for dropdown with null value', () => { - const field = new FormFieldModel(new FormModel(), { - type: FormFieldTypes.DROPDOWN, - value: null, - required: true, - options: [{ id: 'one', name: 'one' }], - selectionType: 'multiple' - }); - - expect(validator.validate(field)).toBe(false); - }); - - it('should fail (display error) for dropdown with empty object', () => { - const field = new FormFieldModel(new FormModel(), { - type: FormFieldTypes.DROPDOWN, - value: {}, - required: true, - options: [{ id: 'one', name: 'one' }], - selectionType: 'multiple' - }); - - expect(validator.validate(field)).toBe(false); - }); - it('should fail (display error) for radio buttons', () => { const field = new FormFieldModel(new FormModel(), { type: FormFieldTypes.RADIO_BUTTONS, diff --git a/lib/core/src/lib/form/components/widgets/core/form-field-validator.ts b/lib/core/src/lib/form/components/widgets/core/form-field-validator.ts index aa28adafdad..01804b25038 100644 --- a/lib/core/src/lib/form/components/widgets/core/form-field-validator.ts +++ b/lib/core/src/lib/form/components/widgets/core/form-field-validator.ts @@ -33,7 +33,6 @@ export class RequiredFieldValidator implements FormFieldValidator { FormFieldTypes.NUMBER, FormFieldTypes.BOOLEAN, FormFieldTypes.TYPEAHEAD, - FormFieldTypes.DROPDOWN, FormFieldTypes.PEOPLE, FormFieldTypes.FUNCTIONAL_GROUP, FormFieldTypes.RADIO_BUTTONS, @@ -51,22 +50,6 @@ export class RequiredFieldValidator implements FormFieldValidator { validate(field: FormFieldModel): boolean { if (this.isSupported(field) && field.isVisible) { - if (field.type === FormFieldTypes.DROPDOWN) { - if (field.hasMultipleValues) { - return Array.isArray(field.value) && !!field.value.length; - } - - if (field.hasEmptyValue && field.emptyOption) { - if (field.value === field.emptyOption.id) { - return false; - } - } - - if (field.required && field.value && typeof field.value === 'object' && !Object.keys(field.value).length) { - return false; - } - } - if (field.type === FormFieldTypes.RADIO_BUTTONS) { const option = field.options.find((opt) => opt.id === field.value); return !!option; diff --git a/lib/core/src/lib/form/components/widgets/error/error.component.scss b/lib/core/src/lib/form/components/widgets/error/error.component.scss index 4687c05c03b..1427d3d9d20 100644 --- a/lib/core/src/lib/form/components/widgets/error/error.component.scss +++ b/lib/core/src/lib/form/components/widgets/error/error.component.scss @@ -1,5 +1,6 @@ .adf-error { display: flex; + align-items: center; &-widget-container { height: auto; diff --git a/lib/process-services-cloud/src/lib/form/components/widgets/dropdown/dropdown-cloud.widget.html b/lib/process-services-cloud/src/lib/form/components/widgets/dropdown/dropdown-cloud.widget.html index 27fe1892fb3..a06b66f5e0e 100644 --- a/lib/process-services-cloud/src/lib/form/components/widgets/dropdown/dropdown-cloud.widget.html +++ b/lib/process-services-cloud/src/lib/form/components/widgets/dropdown/dropdown-cloud.widget.html @@ -1,43 +1,50 @@ -
-
-