Tag Archives: validation

Angularjs Custom Form Validation

update: 9/9/14 added the ng-learn link which has  a flushed out example. If you are doing this you will need to change you test cases and include all the things like you were testing a directive.

If you want to set an input value to be invalid before submission then this is a good resource.

$scope.yourForm.nameOfElement.$setValidity( ‘reason’,  false );

E.G.: You want to add an error to your start date in a search form.

$scope.searchForm.startDate.$setValidity( ‘date’, false );

http://aleaiactaest.ch/2012/08/23/custom-form-validation-in-angular-js/

To see a more fully explained example please see:

http://ng-learn.org/2014/03/Writing_Custom_Validations_Part4/

Click the launch demo button.  Then click the script.js and the spec.js to see the full example.

Advertisements