Revert "AAE-23521 Fix improve dropdown reactive form" (#10068)

* Revert "AAE-23521 Fix improve dropdown reactive form (#10040)"

This reverts commit f88ff10f30.

* Revert "AAE-24371 Fix invalid endpoint is called when process with form is st… (#10052)"

This reverts commit d38e782fe3.

* Revert "Revert "AAE-24371 Fix invalid endpoint is called when process with form is st… (#10052)""

This reverts commit 125ada76f61ab7a258503dbc51d09950073f9a95.
This commit is contained in:
Vito Albano
2024-08-09 15:01:44 +01:00
committed by GitHub
parent 7d741c2634
commit 554218d11e
13 changed files with 331 additions and 466 deletions

View File

@@ -54,7 +54,7 @@ export class FormFieldTypes {
static VALIDATABLE_TYPES: string[] = [FormFieldTypes.DISPLAY_EXTERNAL_PROPERTY];
static REACTIVE_TYPES: string[] = [FormFieldTypes.DATE, FormFieldTypes.DATETIME, FormFieldTypes.DROPDOWN];
static REACTIVE_TYPES: string[] = [FormFieldTypes.DATE, FormFieldTypes.DATETIME];
static CONSTANT_VALUE_TYPES: string[] = [FormFieldTypes.DISPLAY_EXTERNAL_PROPERTY];

View File

@@ -59,6 +59,51 @@ 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,

View File

@@ -33,6 +33,7 @@ export class RequiredFieldValidator implements FormFieldValidator {
FormFieldTypes.NUMBER,
FormFieldTypes.BOOLEAN,
FormFieldTypes.TYPEAHEAD,
FormFieldTypes.DROPDOWN,
FormFieldTypes.PEOPLE,
FormFieldTypes.FUNCTIONAL_GROUP,
FormFieldTypes.RADIO_BUTTONS,
@@ -50,6 +51,22 @@ 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;

View File

@@ -1,6 +1,5 @@
.adf-error {
display: flex;
align-items: center;
&-widget-container {
height: auto;