Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Foolproof cannot perform client-side time validation #18

Open
cesarsouza opened this issue Jun 13, 2020 · 0 comments
Open

Foolproof cannot perform client-side time validation #18

cesarsouza opened this issue Jun 13, 2020 · 0 comments

Comments

@cesarsouza
Copy link

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant