Skip to content

Commit

Permalink
Validation for date-related fields
Browse files Browse the repository at this point in the history
  • Loading branch information
romanblanco committed Jun 18, 2019
1 parent b2a4c8c commit ec8f8c6
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions src/dialog-user/services/dialogData.ts
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,10 @@ export default class DialogDataService {
};
validation.field = field.label;

let dateField = (field.type === 'DialogFieldDateTimeControl' ||
field.type === 'DialogFieldDateControl');
let validDateField = (dateField && _.isDate(field.dateField));

if (field.required) {
if (field.type === 'DialogFieldCheckBox' && fieldValue === 'f') {
validation.isValid = false;
Expand All @@ -162,7 +166,7 @@ export default class DialogDataService {
validation.isValid = false;
validation.message = __('This field is required');
}
} else if (_.isEmpty(fieldValue) && !_.isDate(fieldValue)) {
} else if (_.isEmpty(fieldValue) && !validDateField) {
validation.isValid = false;
validation.message = __('This field is required');
}
Expand All @@ -179,8 +183,7 @@ export default class DialogDataService {
}
}

if (field.type === 'DialogFieldDateControl' &&
!(fieldValue instanceof Date)) {
if (dateField && !validDateField) {
validation.isValid = false;
validation.message = __('Select a valid date');
}
Expand Down

0 comments on commit ec8f8c6

Please sign in to comment.