Created
January 7, 2015 07:15
-
-
Save joedj/00845444f6185de4b93a to your computer and use it in GitHub Desktop.
Nested field validation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"name": "nested_fields", | |
"version": "0.0.1", | |
"private": true, | |
"dependencies": { | |
"forms": "1.1.0" | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
assert = require('assert'); | |
forms = require('forms'); | |
var form = forms.create({ | |
userDetails: { | |
username: forms.fields.string({required: true}), | |
password: forms.fields.password({required: true}) | |
} | |
}); | |
var data = { userDetails: {} }; | |
function callback(f) { | |
assert.equal( | |
'Username is required.', | |
f.fields.userDetails.fields.username.error, | |
'Expected validation failure on username field' | |
); // this assertion passes | |
assert(!f.isValid(), 'Expected form validation error'); // <-- we fail here | |
} | |
form.handle(data, { | |
success: function(f) { | |
callback(f); | |
assert.fail('Unexpected success callback') | |
}, | |
other: callback | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment