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

Popular posts from this blog

assembly - What is the addressing mode for ld, add, and rjmp instructions? -

vowpalwabbit - Interpreting Vowpal Wabbit results: Why are some lines appended by "h"? -

Is there a way to convert an HTML page styled with Bootstrap CSS into email-compatible html? -