I am used to work with JQuery.validation to do validations of form elements. Now that I start using Ember views, I wonder what the best way is to validate fields, highlight fields, show error messages (individual per field or grouped), etc.
I see 4 possibilities:
1. Use Jquery.validation as before: thus in the document.ready, initialize the form validation settings and behavior.
$
$("#registerForm").validate({
rules : {
user_name : "required",
user_email : {
required : true,
email : true
},
},
errorClass : "help-inline",
errorElement : "span",
highlight : function(element, errorClass, validClass) {
$(element).parents('.control-group').removeClass('success');
},
unhighlight : function(element, errorClass, validClass) {
$(element).parents('.control-group').removeClass('error');
}
});
});
2. Create specific Ember views for each individual form element (input, textarea, etc.) and implement highlighting in the view code; but what with the error message in that case ?
3. Create specific Ember views for a group of elements (e.g. a control-group representing a div, an i, an input and a span element and implement highlighting in the view code and also implement show and hide of error messages in that view.
4. Put field validation logic in the controller.
In addition to the above, if the server comes back with a 422 error (server validation), I want to use the same highlighting and error text message possibilities. I think option 3 or 4 is the best way to go, but as I am new to Ember, I would welcome any suggestions/ideas or even better: some code samples.