angularjs - How to send all value of checkboxes on server? -


i have html code generated angular js via ng-repeat:

 <li ng-repeat="(key, item) in data.conditions_list" ng-class="{active: item.active}">             <span class="sbrand-checkbox">                 <input ng-checked="item.active" type="checkbox" ng-model="formdata.conditions[item.id]">             </span>             <label>{{item.name}}</label>   </li> 

this code sets checkboxes on active state if ng-checked="item.active". works.

when checked unchecked element , submit checked default form see:

["conditions"]=>   array(1) {     [5]=>     string(4) "true"   } 

so, means sent thta checkbox have cheked. others not sent on server.

i can as:

html:

<input ng-checked="ischecked(item.active, item.id)" type="checkbox" ng-model="formdata.conditions[item.id]"> 

angular js:

$scope.ischecked = function (item, id){     if(item.active){         $scope.formdata.conditions[id];     } }; 

and after send form $scope.formdata.conditions

this how browser behaves. not submits unchecked checkbox value. has nothing angularjs or javascript.

you can treat absence of checkbox value in request unchecked on server.

an alternative way maintain hidden fields each checkbox , set value on checkbox change , submit these hidden fields server instead of checkboxes.


Comments

Popular posts from this blog

python - TypeError: start must be a integer -

c# - DevExpress RepositoryItemComboBox BackColor property ignored -

django - Creating multiple model instances in DRF3 -