Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Angular.js idiom for disabling button when textarea is blank

I want a button to be disabled unless text is present in a textarea. Here is what I have tried:

<textarea ng-model="shipment_ids"></textarea>
<button ng-click="do_something" ng-disabled="shipment_ids.length"></button>

However, the button is enabled no matter what.

like image 588
ben.coffee Avatar asked Jul 08 '14 22:07

ben.coffee


1 Answers

I think you want the opposite of what your code states. Something like:

<textarea ng-model="shipment_ids"></textarea>
<button ng-click="do_something" ng-disabled="!shipment_ids">Click me</button>

Example on JSFiddle here.

like image 127
David Spence Avatar answered Nov 14 '22 14:11

David Spence