lundi 23 février 2015

Angular multiple checkboxes not passing to model

Within my application I'm allowing users to select a checkbox and also choose additional items from a further list for submission. I'm using the checklistModel directive found at http://ift.tt/1lmEPlk


My current form set up is as follows



<fieldset>
<legend class="mb">Please email me the following brochure:</legend>
<ul>
<li>
<input type="checkbox" checklist-model="formData.selectedFiles.files" checklist-value="selectedFile.id" >
<label>{{ selectedFile.id }} {{ selectedFile.title }}</label>
</li>
</ul>
</fieldset>
<fieldset>
<legend class="mb">I would also like information on the following products:</legend>
<div class="layout">
<div class="layout__item one-half" ng-repeat="files in alternativeFiles">
<ul>
<li ng-repeat="file in files">
<input type="checkbox" checklist-model="formData.selectedFiles.files" checklist-value="file.id">
<label>{{ file.title }}</label>
</li>
</ul>

</div>
</div>
</fieldset>
{{ formData }}


The main section within the ng-repeat for the checkbox list populates the formData fine with an array within {{formData}} populated with correct values. However, if the initial please email the following brochure checkbox is select it passes through a null value.


I have checked and confirmed that the selectedFile.id value for this item is populating correct and if I simply change the value simply to a string or fixed numeric value then the array populates.


Been looking at this for a while and have been tearing my hair out, any suggestions would be very much appreciated.


Thanks in advance.


Simon





Aucun commentaire:

Enregistrer un commentaire