Reputation: 557
In my form i got a dropdown with Yes / NO option , when user selects yes additional input box will be displayed and allows user to enter some value input box.
how can i validate input box using angularjs ngmessages only if it is visible or value in dropdown is 'Yes'?
html code
<div class="col-xs-8">
<select ng-model="userAvailable">
<option value="no">No</option>
<option value="yes">Yes</option>
</select>
<input ng-show="userAvailable == 'yes'" placeholder="If yes , add name?" type="text" class="form-control" />
</div>
Thanks in advance.
Upvotes: 0
Views: 752
Reputation: 558
Try using ng-if
instead of ng-show
. ng-show
removes it from the DOM so the validation doesn't execute on it. ng-show
just hides it.
<input ng-if="userAvailable == 'yes'" placeholder="If yes , add name?" type="text" class="form-control" />
Upvotes: 1