mirror of
https://github.com/Alfresco/alfresco-ng2-components.git
synced 2026-09-09 18:03:21 +00:00
AAE-43391 Disable 'Start process' and 'Complete' when whitespace is entered into required form fields (#11760)
This commit is contained in:
@@ -120,6 +120,26 @@ describe('FormFieldValidator', () => {
|
||||
expect(validator.validate(field)).toBe(false);
|
||||
});
|
||||
|
||||
it('should fail (display error) for text with only whitespace', () => {
|
||||
const field = new FormFieldModel(new FormModel(), {
|
||||
type: FormFieldTypes.TEXT,
|
||||
value: ' ',
|
||||
required: true
|
||||
});
|
||||
|
||||
expect(validator.validate(field)).toBe(false);
|
||||
});
|
||||
|
||||
it('should fail (display error) for multiline text with only whitespace', () => {
|
||||
const field = new FormFieldModel(new FormModel(), {
|
||||
type: FormFieldTypes.MULTILINE_TEXT,
|
||||
value: ' \t\n ',
|
||||
required: true
|
||||
});
|
||||
|
||||
expect(validator.validate(field)).toBe(false);
|
||||
});
|
||||
|
||||
it('should succeed for date', () => {
|
||||
const field = new FormFieldModel(new FormModel(), {
|
||||
type: FormFieldTypes.DATE,
|
||||
|
||||
@@ -72,6 +72,10 @@ export class RequiredFieldValidator implements FormFieldValidator {
|
||||
if (field.value === null || field.value === undefined || field.value === '') {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (typeof field.value === 'string' && field.value.trim().length === 0) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -116,4 +116,40 @@ describe('WidgetComponent', () => {
|
||||
widget.field = new FormFieldModel(null, { required: true });
|
||||
expect(widget.isRequired()).toBeTruthy();
|
||||
});
|
||||
|
||||
describe('isInvalidFieldRequired', () => {
|
||||
it('should return true when required field has no value', () => {
|
||||
widget.field = new FormFieldModel(new FormModel(), {
|
||||
type: 'text',
|
||||
required: true,
|
||||
value: null
|
||||
});
|
||||
widget.field.markAsInvalid();
|
||||
widget.field.validationSummary = null;
|
||||
|
||||
expect(widget.isInvalidFieldRequired()).toBe(true);
|
||||
});
|
||||
|
||||
it('should return true when required field has whitespace-only value', () => {
|
||||
widget.field = new FormFieldModel(new FormModel(), {
|
||||
type: 'text',
|
||||
required: true,
|
||||
value: ' '
|
||||
});
|
||||
widget.field.markAsInvalid();
|
||||
|
||||
expect(widget.isInvalidFieldRequired()).toBe(true);
|
||||
});
|
||||
|
||||
it('should return false when required field has a non-whitespace value', () => {
|
||||
widget.field = new FormFieldModel(new FormModel(), {
|
||||
type: 'text',
|
||||
required: true,
|
||||
value: 'hello'
|
||||
});
|
||||
widget.field.markAsValid();
|
||||
|
||||
expect(widget.isInvalidFieldRequired()).toBe(false);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@@ -88,7 +88,8 @@ export class WidgetComponent implements AfterViewInit {
|
||||
}
|
||||
|
||||
isInvalidFieldRequired() {
|
||||
return !this.field.isValid && (!this.field.validationSummary || !this.field.value) && this.isRequired();
|
||||
const isValueEmpty = !this.field.value || (typeof this.field.value === 'string' && this.field.value.trim().length === 0);
|
||||
return !this.field.isValid && (!this.field.validationSummary || isValueEmpty) && this.isRequired();
|
||||
}
|
||||
|
||||
ngAfterViewInit() {
|
||||
|
||||
Reference in New Issue
Block a user