mirror of
https://github.com/Alfresco/alfresco-ng2-components.git
synced 2025-07-24 17:32:15 +00:00
Revert "Revert "AAE-23521 Fix improve dropdown reactive form"" (#10073)
* Revert "Revert "AAE-23521 Fix improve dropdown reactive form" (#10068)"
This reverts commit 554218d11e
.
* AAE-23521 fix trigger error check
* AAE-23521 improve standalone import
---------
Co-authored-by: Kasia Biernat <kasia.biernat@hyland.com>
This commit is contained in:
@@ -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];
|
||||
|
||||
|
@@ -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,
|
||||
|
@@ -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;
|
||||
|
@@ -1,5 +1,6 @@
|
||||
.adf-error {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
|
||||
&-widget-container {
|
||||
height: auto;
|
||||
|
Reference in New Issue
Block a user