angularjs - How do I toggle field required attribute after ng-click? -
i have dropdown list in repeater should toggle custom "required" attribute. tried ng-show display="none" attribute added. options are:-
1- add/remove input field , set bird.stuff, not hide because still required.
2- add/remove 'required' attribute on input field.
js
$scope.validateparticipants = function (type) { if (type == "single") { this.donation.participants = "1"; } else this.donation.participants = ""; }
html
<div ng-repeat="bird in animaltest.birds"> @(html.dropdownlist("type", (ienumerable<selectlistitem>)viewbag.birdlist, new { ng_model = "bird.type", ng_change = "validaterequired(bird.type)", required = "type required" })) ... <input data-ng-show="bird.type == 'endangered'" id="stuff" type="number" data-ng-model="bird.stuff" required = "number of volunteers required"/> </div>
thanks in advance!
use ng-required. takes angular expression , adds required attribute if expression true.
<input type="number" data-ng-model="bird.stuff" ng-required="donation.participants > 0"/>
Comments
Post a Comment