Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Disable input on button click in angularjs

Tags:

angularjs

HTML

<input type="text" ng-model="email" ng-disabled="button" rquired>
<a class="btn" ng-model="button">edit</a>

So basically I want to enable the input field when the button is clicked. I could do this with some javascript but I want to figure out an easy way for this.

The above example does not work. Any ideas why?

like image 560
UpCat Avatar asked May 24 '13 10:05

UpCat


People also ask

How to deactivate button in Angular?

You can enable or disable the ButtonGroup for Angular. By default, the component is enabled. To disable the whole group of buttons, set the disabled attribute of the ButtonGroup to true . To disable a specific button, set its own disabled attribute to true and leave the disabled attribute of the ButtonGroup undefined.

Is disabled in AngularJS?

AngularJS ng-disabled DirectiveThe ng-disabled directive sets the disabled attribute of a form field (input, select, or textarea). The form field will be disabled if the expression inside the ng-disabled attribute returns true.

How do I disable the button if the input box is empty and enable when field is filled?

Just click f12 in your browser, find the submit button in the html, and then remove the disabled ! It will submit the form even if the inputs are empty.


1 Answers

You can use ng-click to change the value of button:

<input type="text" ng-model="email" ng-disabled="button" required ng-init="button=true">
<a class="btn" ng-click="button=false">enable edit</a>
<a class="btn" ng-click="button=true">disable edit</a>
<a class="btn" ng-click="button=!button">toggle edit</a>
like image 115
joakimbl Avatar answered Sep 25 '22 21:09

joakimbl