I'm interested in validating form (all the fields) on the server side and then sending list of errors back to the client to be displayed. So validation would have to happen at a form level, but validity setting would have to be set per field. I'm not sure how to achieve it, any advices?
1 Answer
AngularJS provides rich custom validation framework.
It exposes the form object within the controller scope and that object has different properties like $error, $dirty, $pristine etc that can be leveraged to create a custom validation solution. Basically all you have to do is get the validation errors from the server and set those properties accordingly.
In your template you would have
<form id="myForm" name="myForm" novalidate ng-controller="myController">
In your controller you would have
scope.myForm.$errors //and so on.
http://docs.angularjs.org/guide/forms
Also use this Chrome extension to inspect the form object at runtime https://chrome.google.com/webstore/detail/angularjs-batarang/ighdmehidhipcmcojjgiloacoafjmpfk?hl=en
7 Comments
input elements in those. If you post a JSFiddle of your app, we can play around.