javascript - How to disable or enable button according to if text boxes empty or not? -
i work on angularjs projerct.
i have button in template , 2 input text elements.
the button have enabled when 2 input boxes has string.
here html code:
<form id="loginform" class="form-horizontal" role="form"> <div style="margin-bottom: 25px" class="input-group"> <span class="input-group-addon"><i class="glyphicon glyphicon-user"></i></span> <input id="login-username" type="text" class="form-control" ng-model="username" placeholder="username"> </div> <div style="margin-bottom: 25px" class="input-group"> <span class="input-group-addon"><i class="glyphicon glyphicon-lock"></i></span> <input id="login-password" type="text" class="form-control" ng-model="password" placeholder="password"> </div> <div style="margin-top:10px" class="form-group pull-left"> <div class="col-sm-12 controls"> <input type="button" class="btn btn-success" value="enter" ng-click="inspectorarea.verify(username,password)" ng-disabled="(username == null || password == null)"> </div> </div> </form>
and here working plunker.
using row ng-disabled="(username == null || password == null)
in input button element disable or enable button.
but not working properly, can see plunker-example, button enabled when text boxes has string first time, if remove string 1 of texts box elements button enable while want them disalbled.
any idea how can disable button if @ least 1 of text boxes empty?
initially username
, password
null. work. when type , delete, become empty , that's why didn't work.
i have modified check truthiness.
<input type="button" class="btn btn-success" value="enter" ng-click="inspectorarea.verify(username,password)" ng-disabled="(!username || !password)">
Comments
Post a Comment