AAE-28918 Fix for start process button is enabled when required widgets are read only without value (#11781)

* AAE-28918 Fix start process button is enabled when required widgets are read only without value

* Apply Copilot review suggestions.

* updates after code review comments

* revert change made earlier
This commit is contained in:
Darren Thornton
2026-04-01 13:32:30 -05:00
committed by GitHub
parent 79871455f4
commit 74252797b7
2 changed files with 60 additions and 17 deletions
@@ -1220,7 +1220,7 @@ describe('FormFieldModel', () => {
}); });
}); });
it('should validate readOnly field if it is validatable', () => { it('should fail validation for readOnly required display-external-property field with null value', () => {
const form = new FormModel(); const form = new FormModel();
const field = new FormFieldModel(form, { const field = new FormFieldModel(form, {
id: 'mockDisplayExternalPropertyFieldId', id: 'mockDisplayExternalPropertyFieldId',
@@ -1233,11 +1233,10 @@ describe('FormFieldModel', () => {
const validator = new RequiredFieldValidator(); const validator = new RequiredFieldValidator();
form.fieldValidators = [validator]; form.fieldValidators = [validator];
expect(FormFieldTypes.isValidatableType(FormFieldTypes.DISPLAY_EXTERNAL_PROPERTY)).toBeTrue();
expect(field.validate()).toBe(false); expect(field.validate()).toBe(false);
}); });
it('should validate NOT readOnly field if it is validatable', () => { it('should fail validation for required display-external-property field with null value', () => {
const form = new FormModel(); const form = new FormModel();
const field = new FormFieldModel(form, { const field = new FormFieldModel(form, {
id: 'mockDisplayExternalPropertyFieldId', id: 'mockDisplayExternalPropertyFieldId',
@@ -1250,11 +1249,10 @@ describe('FormFieldModel', () => {
const validator = new RequiredFieldValidator(); const validator = new RequiredFieldValidator();
form.fieldValidators = [validator]; form.fieldValidators = [validator];
expect(FormFieldTypes.isValidatableType(FormFieldTypes.DISPLAY_EXTERNAL_PROPERTY)).toBeTrue();
expect(field.validate()).toBe(false); expect(field.validate()).toBe(false);
}); });
it('should NOT validate readOnly field if it is NOT validatable', () => { it('should fail validation for readOnly required text field with null value', () => {
const form = new FormModel(); const form = new FormModel();
const field = new FormFieldModel(form, { const field = new FormFieldModel(form, {
id: 'mockTextFieldId', id: 'mockTextFieldId',
@@ -1267,10 +1265,60 @@ describe('FormFieldModel', () => {
const validator = new RequiredFieldValidator(); const validator = new RequiredFieldValidator();
form.fieldValidators = [validator]; form.fieldValidators = [validator];
expect(FormFieldTypes.isValidatableType(FormFieldTypes.TEXT)).toBeFalse(); expect(field.validate()).toBe(false);
});
it('should pass validation for readOnly required field that has a value', () => {
const form = new FormModel();
const field = new FormFieldModel(form, {
id: 'mockTextFieldId',
type: FormFieldTypes.TEXT,
readOnly: true,
required: true,
value: 'some value'
});
const validator = new RequiredFieldValidator();
form.fieldValidators = [validator];
expect(field.validate()).toBe(true); expect(field.validate()).toBe(true);
}); });
it('should pass validation for readOnly non-required field with null value', () => {
const form = new FormModel();
const field = new FormFieldModel(form, {
id: 'mockTextFieldId',
type: FormFieldTypes.TEXT,
readOnly: true,
required: false,
value: null
});
const validator = new RequiredFieldValidator();
form.fieldValidators = [validator];
expect(field.validate()).toBe(true);
});
it('should pass validation for readOnly required field with empty value when field or parent is hidden', () => {
const form = new FormModel();
const field = new FormFieldModel(form, {
id: 'mockTextFieldId',
type: FormFieldTypes.TEXT,
readOnly: true,
required: true,
value: null
});
const validator = new RequiredFieldValidator();
form.fieldValidators = [validator];
spyOn(form, 'isFieldOrParentHidden').and.returnValue(true);
expect(field.validate()).toBe(true);
expect(form.isFieldOrParentHidden).toHaveBeenCalledWith(field);
});
it('should set the tooltip correctly', () => { it('should set the tooltip correctly', () => {
const form = new FormModel(); const form = new FormModel();
const tooltipText = 'This is a tooltip'; const tooltipText = 'This is a tooltip';
@@ -170,23 +170,18 @@ export class FormFieldModel extends FormWidgetModel {
validate(): boolean { validate(): boolean {
this.validationSummary = new ErrorMessageModel(); this.validationSummary = new ErrorMessageModel();
if (this.isFieldValidatable()) { const validators = this.form?.fieldValidators || [];
const validators = this.form.fieldValidators || [];
for (const validator of validators) { for (const validator of validators) {
if (!validator.validate(this)) { if (!validator.validate(this)) {
this._isValid = false; this._isValid = false;
return this._isValid; return this._isValid;
} }
} }
}
this._isValid = true; this._isValid = true;
return this._isValid; return this._isValid;
} }
private isFieldValidatable(): boolean {
return !this.readOnly || FormFieldTypes.isValidatableType(this.type);
}
constructor(form: any, json?: any, parent?: RepeatableSectionModel) { constructor(form: any, json?: any, parent?: RepeatableSectionModel) {
super(form, json); super(form, json);
if (json) { if (json) {