vitalets / checklist-model

AngularJS directive for list of checkboxes
http://vitalets.github.io/checklist-model
MIT License
1.05k stars 206 forks source link

Checkbox does not update when the model is changed in a watcher #137

Closed MacDschie closed 8 years ago

MacDschie commented 8 years ago

I have an array of checkboxes and have to prevent that all of them get unchecked at once. So I wrote a watcher in my controller which just adds one valid item to the array which I use as model in the checklist-model attribute when the array is empty:

$scope.$watchCollection(function() { return that.arrayModel; }, function() { if (that.arrayModel.length === 0) that.arrayModel.push('someValidItem'); });

That works fine, until just this valid item I push is the only one checked and gets unchecked by the user. Then, my watcher is triggered and adds it to the array again, but the corresponding checkbox does not update (it does not get checked, also no watcher gets triggered in the checklist-model.js). The checkbox gets updated only at the same moment when I check another box.

Is there anything I have to do in the watcher to trigger a model update? As I said, the checkbox updates itself correctly, when another item as the one I add in my watcher gets unchecked as the last one, but not when just this item I add gets unchecked.

beradrian commented 8 years ago

For what you're trying to achieve I think you'll better use checklist-before-change. Please check out the documentation https://github.com/vitalets/checklist-model and let me know if that works for you.

MacDschie commented 8 years ago

OK, I'll try that. Thanks for the reply.