1

How to disable the submit button,if radio button is not selecetd.Provided that radio button generates dynamic data from controller using ng-repeat in angularjs

1

3 Answers 3

1

I used ng-required="true" on inputs. And it worked. Take a look at this plunker: http://plnkr.co/edit/NF5j2VC6prUCjRIk5bLW?p=preview

Sign up to request clarification or add additional context in comments.

Comments

0

You can use ng-required on the radiobutton and in the submit button ng-disabled

http://plnkr.co/edit/h7FJljOXSaEjkKZ9L3S9?p=preview

Take a look at the ng-required and ng-disabled directives in this code:

<form name="myForm" ng-submit="submitForm()" ng-controller="ExampleController">
   <input type="radio" ng-model="color" value="red" ng-required="!color">  Red <br/>
   <input type="radio" ng-model="color" value="green" ng-required="!color"> Green <br/>
   <input type="radio" ng-model="color" value="blue" ng-required="!color"> Blue <br/>
   <tt>color = {{color | json}}</tt><br/>
   <button 
   data-ng-disabled="myForm.$invalid"
   type="submit">Submit</button>
  </form>

3 Comments

almost but not working please double check your plnkr
How this plunkr works: if no radiobutton is selected submit button is disabled, if you select one of the options the radio buttons get selected is that the expected behavior?
Well the question is: How to disable the submit button,if radio button is not select, nothing about showing an alert ;-)
0

http://plnkr.co/edit/lPOAaddGNBBOd8c9sWj2?p=preview

<form name="myForm" ng-submit="submitForm()" ng-controller="ExampleController">
       <input type="radio" ng-model="color" value="red" >  Red <br/>
       <input type="radio" ng-model="color" value="green" > Green <br/>
       <input type="radio" ng-model="color" value="blue" > Blue <br/>
       <tt>color = {{color | json}}</tt><br/>
       <button 
       data-ng-disabled="!color"
       type="submit">Submit</button>
      </form>

js:

 angular.module('radioExample', [])
     .controller('ExampleController', ['$scope', function($scope) {
       $scope.color = '';
       $scope.specialValue = {
         "id": "12345",
         "value": "green"
       };

       $scope.submitForm = function() {
         alert('valid');
       }

     }]);

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.