Skip to content

Pre parsing validation #186

Description

@acorbel

I've read the following issue: #166 and I'm wondering how we can enforce type validation (using is module or node-validator).

If you submit an object to a string field, it is viewed as valid ("[Object object]"). Of course, I don't think it is the desired behaviour. What do you think about it?

Or maybe providing a generic field and we add this kind of validation:

exports.typeValidator = function (type, message) {
    if(!is.fn(is[type])) {
        throw new TypeError('this type is not defined');
    } 

    var msg = message || 'Please enter a valid value';
    return function (form, field, callback) {
        if (is[type](field.data)) {
            callback();
        } else {
            callback(msg);
        }
    };
};

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions