jeudi 20 décembre 2018

Add/Remove data from empty array using checklist-model

I have a checklist-model form (multiple checkboxes) in AngularJS that needs to read/add/remove values from an array. The array may have no value or it may have five values. The array values are 20,21,22,23,24. Each value corresponds to the five check boxes. If the array contains '20' then the checkbox input for '20' will be checked, etc...

If I use ng-model instead of checklist-model, it works. The checkbox is checked upon loading the form because formData.observations == 20. When I uncheck the box 20 is removed from the formData.observations array as expected.

When I use checklist-model the checkbox is not checked and clicking the box never removes nor adds the value to the formData.observations array.

[...html]    
<div class="row">                                    
  <div class="col-md-1 col-sm-1 col-xs-1">                                                   
    <input id="observation" type="checkbox" checklist-model="formData.observations" checklist-value="formData.observations[20]" ng-true-value="[20]" ng-false-value="[]">                                                    
    <label for="smelled_observation"></label>                                                
  </div>                                                 
  <div class="col-md-10 col-md-10 col-xs-10">                                                    
    <label class="filter-label" for="observation">Confirmed</label>                                              
  </div>                                         
</div>

[...service]
formData = {
   version: 1,
   observation: [20],
   actionsTaken: [],
   additionalNotes: 'notes...',
   userName: 'John Doe',
   timestamp: 'ISO8061',
}

When the form loads, the checkbox should be 'checked' because formData.observations = 20 (This worked when using ng-model).




Aucun commentaire:

Enregistrer un commentaire