Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to toggle button's state in angular.js?

Tags:

angularjs

What I'm trying to do is to enable submit button If all of the textboxes hold values in them. Disable the submit button otherwise. But the problem here is the number of textboxes may vary (dynamic) so I can not hardcode the models in ng-disabled attribute.

This is what I've tried so far: http://jsfiddle.net/codef0rmer/6uKAT/

Is there any other approach I should follow?

like image 823
codef0rmer Avatar asked Sep 11 '25 06:09

codef0rmer


1 Answers

This is the basic idea.

<form name="myForm">
     Item1: <input ng-model="item1" required/><br/>
     Item2: <input ng-model="item2" required/><br/>
     Item3: <input ng-model="item3" required/><br/>
     <button type="submit" ng-disabled="myForm.$invalid">Submit</button>
</form>
like image 116
Ben Lesh Avatar answered Sep 13 '25 14:09

Ben Lesh