AAE-40741 Form rule Validate form doesn't do anything (#11788)

This commit is contained in:
David Olson
2026-04-06 09:44:23 -05:00
committed by GitHub
parent 74252797b7
commit 70a6f42649
14 changed files with 227 additions and 1 deletions
@@ -79,6 +79,11 @@ describe('FormModel', () => {
expect(form.readOnly).toBeTruthy(); expect(form.readOnly).toBeTruthy();
}); });
it('should have showAllValidationErrors default to false', () => {
const form = new FormModel({});
expect(form.showAllValidationErrors).toBe(false);
});
it('should set form values when variable value is 0', () => { it('should set form values when variable value is 0', () => {
const variables = { const variables = {
pfx_property_one: 0 pfx_property_one: 0
@@ -94,6 +94,7 @@ export class FormModel implements ProcessFormModel {
className: string; className: string;
readOnly = false; readOnly = false;
isValid = true; isValid = true;
showAllValidationErrors = false;
processVariables: ProcessVariableModel[] = []; processVariables: ProcessVariableModel[] = [];
variables: FormVariableModel[] = []; variables: FormVariableModel[] = [];
enableParentVisibilityCheck: boolean = false; enableParentVisibilityCheck: boolean = false;
@@ -526,4 +526,38 @@ describe('DateTimeWidgetComponent', () => {
expect(asterisk?.textContent).toEqual('*'); expect(asterisk?.textContent).toEqual('*');
}); });
}); });
describe('showAllValidationErrors', () => {
it('should mark datetimeInputControl as touched when showAllValidationErrors is true', () => {
widget.field = new FormFieldModel(form, {
id: 'datetime-id',
name: 'datetime-name',
type: FormFieldTypes.DATETIME,
required: true
});
fixture.detectChanges();
expect(widget.datetimeInputControl.touched).toBe(false);
form.showAllValidationErrors = true;
widget.updateReactiveFormControl();
expect(widget.datetimeInputControl.touched).toBe(true);
});
it('should not mark datetimeInputControl as touched when showAllValidationErrors is false', () => {
widget.field = new FormFieldModel(form, {
id: 'datetime-id',
name: 'datetime-name',
type: FormFieldTypes.DATETIME,
required: true
});
fixture.detectChanges();
form.showAllValidationErrors = false;
widget.updateReactiveFormControl();
expect(widget.datetimeInputControl.touched).toBe(false);
});
});
}); });
@@ -71,6 +71,9 @@ export class DateTimeWidgetComponent extends WidgetComponent implements OnInit,
updateReactiveFormControl(): void { updateReactiveFormControl(): void {
this.setFormControlValue(); this.setFormControlValue();
this.updateFormControlState(); this.updateFormControlState();
if (this.field?.form?.showAllValidationErrors) {
this.datetimeInputControl.markAsTouched();
}
this.validateField(); this.validateField();
} }
@@ -340,4 +340,38 @@ describe('DateWidgetComponent', () => {
expect(dateElement.value).toContain('03-02-2020'); expect(dateElement.value).toContain('03-02-2020');
}); });
describe('showAllValidationErrors', () => {
it('should mark dateInputControl as touched when showAllValidationErrors is true', () => {
widget.field = new FormFieldModel(form, {
id: 'date-field-id',
name: 'date-name',
type: FormFieldTypes.DATE,
required: true
});
fixture.detectChanges();
expect(widget.dateInputControl.touched).toBe(false);
form.showAllValidationErrors = true;
widget.updateReactiveFormControl();
expect(widget.dateInputControl.touched).toBe(true);
});
it('should not mark dateInputControl as touched when showAllValidationErrors is false', () => {
widget.field = new FormFieldModel(form, {
id: 'date-field-id',
name: 'date-name',
type: FormFieldTypes.DATE,
required: true
});
fixture.detectChanges();
form.showAllValidationErrors = false;
widget.updateReactiveFormControl();
expect(widget.dateInputControl.touched).toBe(false);
});
});
}); });
@@ -80,6 +80,9 @@ export class DateWidgetComponent extends WidgetComponent implements OnInit, Reac
updateReactiveFormControl(): void { updateReactiveFormControl(): void {
this.updateFormControlState(); this.updateFormControlState();
if (this.field?.form?.showAllValidationErrors) {
this.dateInputControl.markAsTouched();
}
this.validateField(); this.validateField();
} }
@@ -152,4 +152,31 @@ describe('WidgetComponent', () => {
expect(widget.isInvalidFieldRequired()).toBe(false); expect(widget.isInvalidFieldRequired()).toBe(false);
}); });
}); });
describe('isTouched', () => {
it('should return false by default', () => {
widget.field = new FormFieldModel(new FormModel(), { type: 'text' });
expect(widget.isTouched()).toBe(false);
});
it('should return true when touched is set', () => {
widget.field = new FormFieldModel(new FormModel(), { type: 'text' });
widget.markAsTouched();
expect(widget.isTouched()).toBe(true);
});
it('should return true when showAllValidationErrors is set on the form', () => {
const form = new FormModel();
form.showAllValidationErrors = true;
widget.field = new FormFieldModel(form, { type: 'text' });
expect(widget.isTouched()).toBe(true);
});
it('should return false when showAllValidationErrors is false and not touched', () => {
const form = new FormModel();
form.showAllValidationErrors = false;
widget.field = new FormFieldModel(form, { type: 'text' });
expect(widget.isTouched()).toBe(false);
});
});
}); });
@@ -80,7 +80,7 @@ export class WidgetComponent implements AfterViewInit {
} }
isTouched(): boolean { isTouched(): boolean {
return this.touched; return this.touched || !!this.field?.form?.showAllValidationErrors;
} }
hasValue(): boolean { hasValue(): boolean {
@@ -510,4 +510,38 @@ describe('DateCloudWidgetComponent', () => {
expect(widget.field.validationSummary.message).toBe('FORM.FIELD.REQUIRED'); expect(widget.field.validationSummary.message).toBe('FORM.FIELD.REQUIRED');
}); });
}); });
describe('showAllValidationErrors', () => {
it('should mark dateInputControl as touched when showAllValidationErrors is true', () => {
widget.field = new FormFieldModel(form, {
id: 'date-field-id',
name: 'date-name',
type: 'date',
required: true
});
fixture.detectChanges();
expect(widget.dateInputControl.touched).toBe(false);
form.showAllValidationErrors = true;
widget.updateReactiveFormControl();
expect(widget.dateInputControl.touched).toBe(true);
});
it('should not mark dateInputControl as touched when showAllValidationErrors is false', () => {
widget.field = new FormFieldModel(form, {
id: 'date-field-id',
name: 'date-name',
type: 'date',
required: true
});
fixture.detectChanges();
form.showAllValidationErrors = false;
widget.updateReactiveFormControl();
expect(widget.dateInputControl.touched).toBe(false);
});
});
}); });
@@ -88,6 +88,9 @@ export class DateCloudWidgetComponent extends WidgetComponent implements OnInit,
updateReactiveFormControl(): void { updateReactiveFormControl(): void {
this.setFormControlValue(); this.setFormControlValue();
this.updateFormControlState(); this.updateFormControlState();
if (this.field?.form?.showAllValidationErrors) {
this.dateInputControl.markAsTouched();
}
this.validateField(); this.validateField();
} }
@@ -1410,6 +1410,44 @@ describe('DropdownCloudWidgetComponent', () => {
expect(allOptions.length).toEqual(1); expect(allOptions.length).toEqual(1);
}); });
}); });
describe('showAllValidationErrors', () => {
it('should mark dropdownControl as touched when showAllValidationErrors is true', () => {
const form = new FormModel();
widget.field = new FormFieldModel(form, {
id: 'dropdown-id',
name: 'dropdown-name',
type: FormFieldTypes.DROPDOWN,
required: true,
options: fakeOptionList
});
fixture.detectChanges();
expect(widget.dropdownControl.touched).toBe(false);
form.showAllValidationErrors = true;
widget.updateReactiveFormControl();
expect(widget.dropdownControl.touched).toBe(true);
});
it('should not mark dropdownControl as touched when showAllValidationErrors is false', () => {
const form = new FormModel();
widget.field = new FormFieldModel(form, {
id: 'dropdown-id',
name: 'dropdown-name',
type: FormFieldTypes.DROPDOWN,
required: true,
options: fakeOptionList
});
fixture.detectChanges();
form.showAllValidationErrors = false;
widget.updateReactiveFormControl();
expect(widget.dropdownControl.touched).toBe(false);
});
});
}); });
describe('DropdownCloudWidgetComponent instantiated by FormFieldComponent wrapper', () => { describe('DropdownCloudWidgetComponent instantiated by FormFieldComponent wrapper', () => {
@@ -165,6 +165,9 @@ export class DropdownCloudWidgetComponent extends WidgetComponent implements OnI
this.setFormControlValue(); this.setFormControlValue();
this.updateFormControlState(); this.updateFormControlState();
if (this.field?.form?.showAllValidationErrors) {
this.dropdownControl.markAsTouched();
}
this.handleErrors(); this.handleErrors();
} }
@@ -349,4 +349,42 @@ describe('DropdownWidgetComponent', () => {
}); });
}); });
}); });
describe('showAllValidationErrors', () => {
it('should mark dropdownControl as touched when showAllValidationErrors is true', () => {
const form = new FormModel();
widget.field = new FormFieldModel(form, {
id: 'dropdown-id',
name: 'dropdown-name',
type: FormFieldTypes.DROPDOWN,
required: true,
options: fakeOptionList
});
fixture.detectChanges();
expect(widget.dropdownControl.touched).toBe(false);
form.showAllValidationErrors = true;
widget.updateReactiveFormControl();
expect(widget.dropdownControl.touched).toBe(true);
});
it('should not mark dropdownControl as touched when showAllValidationErrors is false', () => {
const form = new FormModel();
widget.field = new FormFieldModel(form, {
id: 'dropdown-id',
name: 'dropdown-name',
type: FormFieldTypes.DROPDOWN,
required: true,
options: fakeOptionList
});
fixture.detectChanges();
form.showAllValidationErrors = false;
widget.updateReactiveFormControl();
expect(widget.dropdownControl.touched).toBe(false);
});
});
}); });
@@ -100,6 +100,9 @@ export class DropdownWidgetComponent extends WidgetComponent implements OnInit,
updateReactiveFormControl(): void { updateReactiveFormControl(): void {
this.updateFormControlState(); this.updateFormControlState();
if (this.field?.form?.showAllValidationErrors) {
this.dropdownControl.markAsTouched();
}
this.handleErrors(); this.handleErrors();
} }