caolan / caolan/forms

Pre parsing validation

Open
#186 4 comments 0 reactions 0 assignees View on GitHub
Dominant language
JavaScript
Stars
1k
Forks
161
PR merge metrics
No merged PRs in 30d

Description

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);
}
};
};
```

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.