You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
angular-validation is damn neat in terms
of validating your forms. I personally hate making my html too much declarative especially
for long forms.
Schema validator is a provider on top of angular-validation letting you control from forms using schema.
Example
// Angular validationvarapp=angular.module('yourApp',['validation','validation.rule']);// Now injecting valiation.schemavarapp=angular.module('yourApp',['validation','validation.rule','validation.schema']);
Your Schema
// Defining schema varAuthor={firstname: {'validations': 'required','validate-on': 'submit','messages':{'required': {'error':'We need it','success': 'All good'}}},url:{'validations': 'required,url','validate-on': 'submit','messages':{'required': {'error':'We need it','success': 'All good'},'url':{'error':'It must be a url'}}}};app.config(function(validationSchemaProvider){validationSchemaProvider.set("Author",Author);});
You see how much we have cut down by using globals, as they apply rules globally on all fields.
Tiny Templating
We all like personalized error messages, and using globals it will be difficult to show personalized
messages. So by using this tiny helper %field% you can print field name.
So %field% is required on firstname with turn out to be firstname is required.
That is all you need , rest of the stuff will work as specified in angular-valiation docs , it is just a provider to remove validations from html to schema.