Check box not (un)checking propertly

Hi,

I put simple check in function on check in my check box list:

$scope.pushNotificationChange = function(item) {
    var limit = 3;
    var length = Settings.getSize();
    var checkedcount=0
    for (var i=0; i<length; i++)
        checkedcount+=( Settings.get(i).checked)? 1 : 0
    if (checkedcount>=limit){
        alert("You can only select a maximum of "+limit+" checkboxes")
        Settings.get(item.id-1).checked = false;
    }
    Settings.save();
};

Functions in services looks like

save: function() {
window.localStorage[ā€˜interesā€™] = JSON.stringify(_settings);
$rootScope.$broadcast(ā€˜interes.changedā€™, _settings);
},
// Get a settings val
get: function(k) {
return _settings[k];
},
// Set a settings val
set: function(k, v) {
_settings[k] = v;
this.save();
},

The problem is that line Settings.get(item.id-1).checked = false; want uncheck the item but if I put Settings.get(item.id).checked = false; it will uncheck the next item that is after the checked oneā€¦

Is there some prohibition that state of check canā€™t be changed on item where check is currently done ?

Could you put up a simple CodePen sample of that? Itā€™s hard to understand and visualize without something to look at.

You could start by forking this : http://codepen.io/ionic/pen/hqcju

1 Like

I skipped part of the app where Iā€™m working with check boxes for a time. The problem in http://codepen.io/ionic/pen/hqcju example, is that HTML5 element is set to true value, and you can see that JSON output is correct written but there is missing visual check mark. The ā€œPush Notificationā€ is correctly checked and outputted in ng-repeat logic is not the same. I think that this is also problem in my case.

Do you know how can I solve this ?

Regards,

Looks like you need to remove the ng-checked attribute from the ion-checkbox tag and it works just fine.

1 Like

Thnx a lot, that was quite simpleā€¦ anyway I donā€™t see purpose of this attribute in this example, it is a little bit confusing to use it in ng-repeate.