7

I have some checkboxes and their value is in database are 'Y' or 'N' as enum.for making updation i have to review all the checkboxes.how to view checkboxes as checked. this is code for checkboxes

<label class="radio-inline">
  <input type="checkbox"  ng-model="newItem.have_voter_id"  value="have_voter_id" /><?php echo $this->lang->line('label_voter_id'); ?>
</label>
<label class="radio-inline">
  <input type="checkbox"   ng-model="newItem.have_passport" value="passport" /> <?php echo $this->lang->line('label_passport'); ?>
 </label>

and this is the function for view and updation

 $scope.edit = function(id,family_id) {

    $scope.action = 'update';
    FamilyMem.get({id:id,family_id:family_id}, function (response) { // success            
        $scope.newItem = response.data; // store result to variable            
          $("#myModal").modal('show');
        }, function (error) { // ajax loading error
            Data.errorMsg(); // display error notification
            //$scope.edit = false;
        });
  };

and edit button

  <a href="" class="btn btn-magenta btn-sm" ng-click="edit(family_member.id,family_member.family_id)">

3 Answers 3

19

Use ng-checked for check-boxes,

<label class="radio-inline">
  <input type="checkbox"  ng-model="newItem.have_voter_id"  value="have_voter_id" ng-checked="newItem.have_voter_id=='Y'"/><?php echo $this->lang->line('label_voter_id'); ?>
</label>

<label class="radio-inline">
  <input type="checkbox"   ng-model="newItem.have_passport" value="passport" ng-checked="newItem.have_passport=='Y'"/> <?php echo $this->lang->line('label_passport'); ?>
</label>
Sign up to request clarification or add additional context in comments.

Comments

0

The model newItem.have_voter_id and newItem.have_passport is set to true or false according to your action on the checkbox. If the checkbox of 'voter_id' is checked then the value of the model newItem.have_voter_id will be updated to true and if unchecked the value will be updated to false. And the same goes for the other checkbox.

2 Comments

for saving the values from checkbox i have done that.but while i want to update it shows again as unchecked even it is true in database
Could you please make a fiddle? It's difficult to find out the problem with these less code.
0

The below link helped me a lot.

You need to initialize model and then if model value match with value it will be get selected.

1 Comment

The below link helped me a lot. You need to initialize model and then if model value match with value it will be get selected.jsfiddle.net/BinaryMuse/ZQDts/3

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.