Skip to content

Commit

Permalink
If any field validator functions have a forceValidation property set,…
Browse files Browse the repository at this point in the history
… validate even when empty.
  • Loading branch information
ljharb committed Jul 28, 2013
1 parent 70a5560 commit 8fc81ce
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion lib/fields.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,10 @@ exports.string = function (opt) {
b.value = raw_data;
b.data = b.parse(raw_data);
b.validate = function (form, callback) {
if (raw_data === '' || raw_data === null || typeof raw_data === 'undefined') {
var forceValidation = (b.validators || []).some(function (validator) {
return validator.forceValidation;
});
if (!forceValidation && (raw_data === '' || raw_data === null || typeof raw_data === 'undefined')) {
// don't validate empty fields, but check if required
if (b.required) { b.error = 'This field is required.'; }
process.nextTick(function () { callback(null, b); });
Expand Down

0 comments on commit 8fc81ce

Please sign in to comment.