Last active
August 29, 2015 14:02
-
-
Save heymichaelp/c7003193c0bdf40e4232 to your computer and use it in GitHub Desktop.
Form Objects: Example of Validator API
This file contains hidden or 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
// Client-side | |
var validator = new NewStudentFormValidator().validate(data) | |
if (validator.isValid()) { | |
// submit form to server | |
} else { | |
// show errors to user | |
} | |
// Server-side (application route) | |
var validator = new NewStudentFormValidator().validate(data) | |
if (validator.isValid()) { | |
return new CreateNewStudent(data).run() | |
// send user to success page | |
} else { | |
// send user back to the form page with errors | |
} | |
// Server-side (API route) | |
var validator = new NewStudentFormValidator().validate(data) | |
if (validator.isValid()) { | |
return new CreateNewStudent(data).run() | |
// send 201 with new student JSON | |
} else { | |
// send error code | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment