Check box not (un)checking propertly


#1

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 ?


#2

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


#3

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,


#4

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


#5

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.