angularjs - validate form only if any radio button is select -
angularjs - validate form only if any radio button is select -
i want enable form's ok button if of checkbox checked, not sure why not working. here code
<form id="myform" class="form-horizontal" role="form" name="myform" novalidate> <li ng-repeat="i in templates"> <input name="mytemplate" ng-model="mytemplate" type="radio" ng-value="{{i.id}}" /> <span>{{i.name}}</span> </li> <button ng-disabled="!templates.length || !mytemplate" ng-class="{'disabled' : !templates.length || !mytemplate}" class="btn btn-primary ok-btn"> submit </button> </form> submit button disabled whether check radio button or not
you need utilize object instead of value in ng-model.
js:
$scope.mytemplate = {};; $scope.templates = [ {id: 1, name: 'one'}, {id: 2, name: 'two'}, {id: 3, name: 'three'} ]; html:
<form id="myform" class="form-horizontal" role="form" name="myform" novalidate> <li ng-repeat="i in templates"> <input name="mytemplate" ng-model="mytemplate.value" type="radio" ng-value="{{i.id}}" /> <span>{{i.name}}</span> </li> <button ng-disabled="!templates.length || !mytemplate.value" ng-class="{'disabled' : !templates.length || !mytemplate}" class="btn btn-primary ok-btn"> submit </button> </form> demo: http://plnkr.co/edit/ekh2aapioecplfxosmhq?p=preview angularjs
Comments
Post a Comment