mercredi 25 mai 2016

How to display checkbox results according to my database model?

I have two variables, one stores the chexboxes and the other stores the values checked, I found a problem to display the checkboxes and their values (checked, not checked) from the controller to the view. I have this code on the controller

$scope.infoParticipant = functionThatGetsParticipants();
           for (var i = 0; i < $scope.infoParticipant.length; i++) {
                    if ($scope.infoParticipant[i].ch_type == 'checkbox_multiple') {
                            var optionsString = $scope.infoParticipant[i].cf_multiple_optionsList;
                            $scope.infoParticipant[i].optionsTab = optionsString.split(";");
                            var optionsSelected = $scope.infoParticipant[i].v_value.split(";");
                    }
}

In the precedent code these should be the values

optionsString = "ch1;ch2;ch3";
$scope.infoParticipant[i].v_value = "ch1;ch2";

According to this the checkboxes :ch1 and ch2 will be checked on the next view :

      <div ng-show="l.ch_type=='checkbox_multiple'">
            <label >My checkboxes</span></label>

            <div class="row" ng-repeat="k in l.optionsTab">

            <div class=" col-md-2 modal_style_input"> </div> 
            <div class="col-md-2"><input type="checkbox" name="option" class="md-input" id="option "  class="wizard-icheck" value="" icheck ng-model="" /></div>
            <div class="col-md-8"></div>

            </div>
        </div>

My question is how to modify my controller and what to put on ng-model to have my correct chexboxes checked?

Thanks in advance.




Aucun commentaire:

Enregistrer un commentaire