[ADF-2501] Checkbox form Widget - TASK "Complete" button not grayed out when widget set as required. (#3161)

* Validation missing for the boolean type.
* Added test cases for the recent changes
This commit is contained in:
siva kumar
2018-04-10 15:04:41 +05:30
committed by Maurizio Vitale
parent 4293bbba83
commit 2b8f12fa57
2 changed files with 28 additions and 0 deletions

View File

@@ -172,6 +172,29 @@ describe('FormFieldValidator', () => {
expect(validator.validate(field)).toBeTruthy();
});
it('should succeed for check box', () => {
let field = new FormFieldModel(new FormModel(), {
type: FormFieldTypes.BOOLEAN,
required: true,
value: true,
options: [{ id: 'two', name: 'two' }]
});
expect(validator.validate(field)).toBeTruthy();
});
it('should fail for check box', () => {
let field = new FormFieldModel(new FormModel(), {
type: FormFieldTypes.BOOLEAN,
required: true,
value: false,
options: [{ id: 'two', name: 'two' }]
});
field.value = false;
expect(validator.validate(field)).toBeFalsy();
});
});
describe('NumberFieldValidator', () => {

View File

@@ -34,6 +34,7 @@ export class RequiredFieldValidator implements FormFieldValidator {
FormFieldTypes.TEXT,
FormFieldTypes.MULTILINE_TEXT,
FormFieldTypes.NUMBER,
FormFieldTypes.BOOLEAN,
FormFieldTypes.TYPEAHEAD,
FormFieldTypes.DROPDOWN,
FormFieldTypes.PEOPLE,
@@ -76,6 +77,10 @@ export class RequiredFieldValidator implements FormFieldValidator {
return field.value && field.value instanceof Array && field.value.length > 0;
}
if (field.type === FormFieldTypes.BOOLEAN) {
return field.value ? true : false;
}
if (field.value === null || field.value === undefined || field.value === '') {
return false;
}