Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Made sure preValidate handles null value. Updated readme with correct…

… return values for preValidate. Closes #80
  • Loading branch information...
commit becdd9c93a4e1691521165e728c2c48555a50bcc 1 parent bf4615f
@thedersen authored
Showing with 8 additions and 1 deletion.
  1. +1 −1  README.md
  2. +7 −0 tests/preValidate.js
View
2  README.md
@@ -211,7 +211,7 @@ model.isValid(['name', 'age']);
Sometimes it can be useful to check (on each key press) if the input is valid - without changing the model - to perform some sort of live validation. You can execute the set of validators for an attribute by calling the `preValidate` method and pass it the name of the attribute and the value to validate.
-If the value is not valid, the error message is returned, otherwise it returns undefined.
+If the value is not valid, the error message is returned (truthy), otherwise it returns a falsy value.
```js
var errorMessage = model.preValidate('attributeName', 'Value');
View
7 tests/preValidate.js
@@ -17,6 +17,9 @@ buster.testCase("preValidate", {
validation: {
name: {
required: true
+ },
+ authenticated: {
+ required: false
}
}
});
@@ -34,6 +37,10 @@ buster.testCase("preValidate", {
"returns nothing when attribute pre-validated has no validation": function(){
refute(this.model.preValidate('age', 2));
+ },
+
+ "handles null value": function() {
+ refute(this.model.preValidate('authenticated', null));
}
}
});
Please sign in to comment.
Something went wrong with that request. Please try again.