Ng-disabled doesn't work for radio buttons and checkboxes

I am working on an AngularJS application. I am trying to create a page that allows the user to select one of three radio buttons. Two of the three also have checkboxes below them to allow the user to select additional options if they have selected the appropriate radio button. To try and prevent the checkbox from being selected incorrectly, I am trying to set the ng-disabled attribute on checkboxes. It doesn't work so far and I've tried several different iterations.

This is my HTML:

    <div class="panel-body">
        <input type="radio" id="notFraudulent" name="actionSelector" ng-model="cleared" /><label for="notFraudulentRadio"> Not Fraudulent</label><br />
        <input type="checkbox" id="highVolumeCustomer" ng-model="highVolumeCustomer" ng-disabled="(fraudulent||cleared)" /><label for="highVolumeCustomer"> High Volume Customer</label><br />
        <br/>
        <input type="radio" id="appearsFraudulent" name="actionSelector" ng-model="fraudulent" /><label for="isFraudulentRadio"> Appears Fraudulent</label><br />
        <input type="checkbox" id="reportAccount" ng-model="reportAccount" ng-disabled="(cleared||reviewed)" /><label for="reportAccount"> Report Account</label><br />
        <br/>
        <input type="radio" id="markReviewed" name="actionSelector" ng-model="reviewed" /><label for="markReviewed"> Mark As Reviewed For Later</label>
    </div>

      

I tried to change the ng-disabled expression operator to & & as I saw some articles where he suggested that the operators don't mean what they think they mean. But it doesn't work, and it doesn't work either if I put only one condition in the expression. There is nothing in the controller yet that tries to use or manipulate any of the ng models in HTML. I have come to the conclusion that there is something I am missing in regards to the radio button, but I can’t let life define me that.

Can anyone see what is my mistake?

+3


source to share


1 answer


you have to use the property value

to bind a custom value for the radio button, and when the radio status changes, the value will persist to ng-model

.

see the code snippet below:



angular.module("app", [])
  .controller("myCtrl", function($scope) {
    $scope.selectedValue = 'cleared';
    $scope.cleared = false;
    $scope.fraudulent = false;
    $scope.reviewed = false;
  });
      

<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script>
<div class="panel-body" ng-app='app' ng-controller="myCtrl">
  <input type="radio" id="notFraudulentRadio" name="actionSelector" value="cleared" ng-model="selectedValue" /><label for="notFraudulentRadio"> Not Fraudulent</label><br />
  <input type="checkbox" id="highVolumeCustomer" ng-model="highVolumeCustomer" ng-disabled="selectedValue === 'fraudulent' || selectedValue === 'cleared'" /><label for="highVolumeCustomer"> High Volume Customer</label><br />
  <br/>
  <input type="radio" id="isFraudulentRadio" name="actionSelector" value="fraudulent" ng-model="selectedValue"/><label for="isFraudulentRadio"> Appears Fraudulent</label><br />
  <input type="checkbox" id="reportAccount" ng-model="reportAccount" ng-disabled="selectedValue === 'cleared' || selectedValue === 'reviewed'" /><label for="reportAccount"> Report Account</label><br />
  <br/>
  <input type="radio" id="markReviewed" name="actionSelector" value="reviewed" ng-model="selectedValue"/><label for="markReviewed"> Mark As Reviewed For Later</label>
  <br>
  cleared:{{cleared}}<br>
  fraudulent:{{fraudulent}}<br>
  reviewed:{{reviewed}}<br>
  selectedValue: {{selectedValue}}
</div>
      

Run codeHide result


+2


source







All Articles