Using NG-repeat to create a form with multiple radio buttons: want to reset the value of all radio buttons

I have a problem with Angular; I have multiple actors, and each actor makes a radio box shape with three options: sacrifice, execution, and both.

Relevant template:

        <div class="actor" ng-repeat="activeActor in activeActors">                                                 
          <p class="category">{{activeActor}}</p>
          <form name="radioButtonForm">
            <div class="causerRadioForm">
              <input type="radio" name="causerRadio" value="victum" ng-model="defaultRadioButton" ng-click="setActorCauser(activeActor, 'victum')">
            </div>

            <div class="causerRadioForm">
              <input type="radio" name="causerRadio"  value="causer" ng-model="defaultRadioButton" ng-click="setActorCauser(activeActor, 'causer')">
            </div>

            <div class="causerRadioForm">
              <input type="radio"  name="causerRadio" value="both" ng-model="defaultRadioButton" ng-click="setActorCauser(activeActor, 'both')">
            </div>

          </form>

        </div>

      

This works great, but I have a button where if I click on it, multiple participants (called fastActors) get rendered and have a default victum.

The problem is that when I select one actor and for example put it in the reason and then click on fastActors the radio camera stays on the camera and the radio button should reset to reach.

Corresponding JS

$scope.toggleFastTraffic = function(actor){
  //erase all actors 
  $scope.actors = [];
  $scope.report.traffic_players = [];
  //default value for radio boxes
  $scope.defaultRadioButton = "victum";


  $scope.SlowTraffic = false;
  $scope.FastTraffic = true;
  $scope.formOptionsExpanded = true;
  $scope.activeActors = [];

  var i = $scope.activeActors.indexOf(actor);
  console.log($scope.activeActors.indexOf(actor));
  if ($scope.counter === -1){

   //do more here
}

      

Basically when I click toggleFastActor, I want to make all the radio buttons victum.

Friendly greetings, T

PS I know that I won a victory over me. I submit to keep this: P

Here is a quick code, it is not finished yet, but it contains a bug: if you click on the car and make it the cause and then switch fast traffic, the car will be sacrificed in the report (which is good), but the switches do not change.

Ps codepen has some other bugs and you shouldn't pay attention to them either.

http://codepen.io/CMD-Thomas/pen/yNbNaZ?editors=101

+3


source to share


1 answer


This is because the ng-model value is. Once you set the value of 'defaultRadioButton' to 'causer', it remains the reason for everyone. Remember the MVVM pattern



+1


source







All Articles