While the library can perform client-side date validation, validating fields marked with [DataType(DataType.Time)]
and rendered as times (e.g., in the format "hh : mm") will not validate correctly.
To solve this issue, I performed the following changes to mvcfoolproof.core.js
:
- Added a "isTime" function right above the isDate local function:
var isTime = function (input) {
return moment(input, ['h:m a', 'H:m']).isValid();
};
- Changed the checks below that region from:
if (isDate(value1)) {
value1 = Date.parse(value1);
value2 = Date.parse(value2);
} else if (isBool(value1)) {
if (value1 == "false") value1 = false;
if (value2 == "false") value2 = false;
value1 = !!value1;
value2 = !!value2;
}
...
to
if (isTime(value1)) {
value1 = moment(value1, ['h:m a', 'H:m']);
value2 = moment(value2, ['h:m a', 'H:m']);
}
else if (isDate(value1)) {
value1 = Date.parse(value1);
value2 = Date.parse(value2);
}
...
and now it works. The bad thing about the above is that I have introduced a dependency on moment.js, I don't know if was already used by the library before.
Hope this can help other people also trying to validate hour/minute intervals.