javascript - Disable required attribute on one radio button -


i have 3 radio buttons in bootstrap modal , want 2 of them required in order submit form. created requiredcheck() function that's using jquery implementation i'd rather not use this. best way disable required attribute 1 radio button, when using angularjs?

html

<form name="jawn">       <div class="modal-header">         <h3 class="modal-title">jawn</h3>       </div><!-- /modal-header -->       <div class="modal-body">         <ul>           <li ng-repeat="item in items">             <label for="optionsradios">                 <input type="radio" ng-model="$parent.data.status" name="optionsradios" ng-value="item.id" required/ ng-click="requiredcheck()"> {{item.name}}             </label>           </li>         </ul>         <h4>comment</h4>         <textarea ng-class="{error: thing.comment.$dirty && thing.comment.$invalid}" type="text" rows="3" cols="64" ng-model="data.comment" ng-minlength="4" ng-required></textarea>         <span class="error" ng-show="thing.comment.$error.required">required</span>       </div><!-- /modal-body-->       <div class="modal-footer">         <button type="submit" class="btn btn-warning" ng-click="ok()" ng-disabled="thing.$invalid">part jawn</button>         <button type="button" ng-click="cancel()" class="btn btn-default">cancel</button>       </div>     </form> 

javascript

angular.module('app') .controller('modalcontroller', function($scope, $modalinstance, $timeout) {   'use strict';    $scope.item = 0;    $scope.items = [     "zero": 0,     "uno": 1,     "dos": 2   ];    $scope.requiredcheck = function () {     var $btnwarning = $('.btn-warning');     var $textarea = $('textarea');     $timeout(function() {       if($scope.data.status === item.dos) {         $btnwarning.removeattr('disabled');         $textarea.removeattr('required');       } else if ($scope.data.status === 3) {         $btnwarning.prop('disabled',true);         $textarea.prop('required', true);       } else if ($scope.data.status === 3) {         $btnwarning.prop('disabled',true);         $textarea.prop('required', true);       }     },100);   };    $scope.ok = function () {    };    $scope.cancel = function () {     $modalinstance.dismiss('cancel');     $modalinstance.close();   };  }); 

you should use approach. have specified ngrequired set true/false controller.

from docs

ngrequired: sets required attribute if set true

html

<textarea ng-model="data.comment" ng-required="textrequired"></textarea> 

script

$scope.requiredcheck = function () {     if(condition){         $scope.textrequired = false;     }else{         $scope.textrequired = true;     }        }; 

note: have simplified answer


Comments

Popular posts from this blog

twig - Using Twigbridge in a Laravel 5.1 Package -

jdbc - Not able to establish database connection in eclipse -

firemonkey - How do I make a beep sound in Android using Delphi and the API? -