mirror of
https://github.com/Alfresco/alfresco-ng2-components.git
synced 2025-07-24 17:32:15 +00:00
AAE-30596 Fix required reactive widgets do not visibility conditions (#10595)
* AAE-30596 Fix required reactive widgets do not visibility conditions * fix unit test
This commit is contained in:
@@ -179,6 +179,24 @@ describe('DropdownWidgetComponent', () => {
|
||||
|
||||
expect(element.querySelector('.adf-invalid')).toBeFalsy();
|
||||
});
|
||||
|
||||
it('should be valid when field is hidden with empty value', () => {
|
||||
widget.field.isVisible = false;
|
||||
fixture.detectChanges();
|
||||
|
||||
expect(widget.field.isValid).toBeTrue();
|
||||
expect(widget.dropdownControl.valid).toBeTrue();
|
||||
expect(widget.field.validationSummary.message).toBe('');
|
||||
});
|
||||
|
||||
it('should be invalid when field is hidden with empty value', () => {
|
||||
widget.field.isVisible = true;
|
||||
fixture.detectChanges();
|
||||
|
||||
expect(widget.field.isValid).toBeFalse();
|
||||
expect(widget.dropdownControl.valid).toBeFalse();
|
||||
expect(widget.field.validationSummary.message).toBe('FORM.FIELD.REQUIRED');
|
||||
});
|
||||
});
|
||||
|
||||
describe('when template is ready', () => {
|
||||
|
@@ -150,7 +150,7 @@ export class DropdownWidgetComponent extends WidgetComponent implements OnInit,
|
||||
}
|
||||
|
||||
private updateFormControlState(): void {
|
||||
this.dropdownControl.setValidators(this.isRequired() ? [this.customRequiredValidator(this.field)] : []);
|
||||
this.dropdownControl.setValidators(this.isRequired() && this.field?.isVisible ? [this.customRequiredValidator(this.field)] : []);
|
||||
this.field?.readOnly || this.readOnly
|
||||
? this.dropdownControl.disable({ emitEvent: false })
|
||||
: this.dropdownControl.enable({ emitEvent: false });
|
||||
|
Reference in New Issue
Block a user