Monday, January 23, 2017

Angular JS - Control form submit when input controls have validation errors

Did you happen to come across this scenario while using AngularJS, where you cannot stop the form being submitted even when the input controls have validation errors? Follow the below updates.

Remove the save data method from the button control. And control to the form using ng-submit

Old code

<input type="button" value="Save" name="Save" ng-click="vm.mySaveFunction()" />

Updated form code

<form name="mySampleForm" ng-submit="mySampleForm.$valid && vm.mySaveFunction()">

<input type="submit" value="Save" name="Save" />

No comments:

Post a Comment