3

I have one problem.I can not select multiple radio button using Angular.js.I am explaining my code below.

<div class="input-group bmargindiv1 col-md-12">
     <label class="checkbox-inline">
     <input type="radio" name="favoriteColors" ng-model="discountPrice" value="true" ng-click="disInclusive();">Discount inclusive
     </label>
     <label class="checkbox-inline">
     <input type="radio" name="favoriteColors" ng-model="discountPrice" value="false" ng-click="disInclusive();">Discount Exclusive
     </label>
 </div>
<div class="input-group bmargindiv1 col-md-12" ng-show="billdata.uncp.$valid && billdata.discount.$valid && billdata.unsp.$valid && billdata.ulsp.$valid && billdata.quantity.$valid && billdata.prcode.$valid">
  <input type="radio" name="favoriteColors" ng-model="isChecked" value="true" ng-required="!isChecked">Add new stock
  <input type="radio" name="favoriteColors" ng-model="isChecked" value="false" ng-required="!isChecked">Update stock 
</div>

My controller side code is given below.

$scope.disInclusive=function(){
        //console.log('hii',$scope.unit_sale_price==null,$scope.discount==null);
        if(($scope.unit_sale_price != '' && $scope.unit_sale_price !=null)  && ($scope.discount !='' && $scope.discount !=null)){
            //console.log('hello');
            if($scope.discountPrice=='false'){
                var price=(parseInt($scope.discount)/100)*(parseInt($scope.unit_sale_price));
                $scope.latest_sale_price=parseInt($scope.unit_sale_price)-price;
            }
            if($scope.discountPrice=='true'){
                $scope.latest_sale_price=$scope.unit_sale_price;
            }
        }else{
            //console.log('hii else');
            if($scope.discount =='' || $scope.discount ==null){
                alert('Please add the discount');
                return;
            }
            if($scope.unit_sale_price =='' || $scope.unit_sale_price ==null){
                alert('Please add the unit sale price');
                return;
            }
        }
    }

Here i have 2 set of radio buttons.I need to select one of each.Here my problem is suppose i selected one radio button from 1st set and when i am selecting second radio button from second set the first one is disappearing.Here i need to select one of each set.Please help me.

2
  • Can you please post also your controller? One quick note: you have set the model isChecked to be true or false and it will always display a required error if you have selected the second option Commented Jan 2, 2016 at 11:03
  • @Nora : i have declared one click event function in controller side for the radio button and that posted above.Please check. Commented Jan 2, 2016 at 11:07

1 Answer 1

4

You used the same name favoriteColors for all the radio buttons in both the groups. You should use a different name for the radio buttons in second group

    <div class="input-group bmargindiv1 col-md-12">
     <label for="discount1" class="checkbox-inline"> Discount inclusive </label>
     <input type="radio" id="discount1" name="discounts" 
            ng-model="discountPrice" ng-value="true" 
            ng-click="disInclusive();">

     <label for="discount2" class="checkbox-inline"> Discount Exclusive </label>
     <input type="radio" id="discount2" name="discounts" 
            ng-model="discountPrice" ng-value="false" 
            ng-click="disInclusive();">
   </div>

  <div class="input-group bmargindiv1 col-md-12">
    <input type="radio" name="stocks" ng-model="isChecked" 
           ng-value="true" ng-required="!isChecked">Add new stock
    <input type="radio" name="stocks" ng-model="isChecked" 
           ng-value="false" ng-required="!isChecked">Update stock 
  </div>
Sign up to request clarification or add additional context in comments.

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.