Created
November 12, 2014 17:14
-
-
Save carlosfilho88/d7ec7fad97a08f09dc5f to your computer and use it in GitHub Desktop.
Multiple checkbox jquery + zend form multiple checkbox (ZF1)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var checkboxes = function() { | |
var items = new Array(); | |
return { | |
"add": function(val) { | |
items.push(val); | |
}, | |
"addUnique": function(val) { | |
Array.prototype.inArray = function(comparer) { | |
for(var i = 0; i < this.length; i++) { | |
if(comparer(this[i])) return true; | |
} | |
return false; | |
}; | |
Array.prototype.pushIfNotExist = function(element, comparer) { | |
if (!this.inArray(comparer)) { | |
this.push(element); | |
} | |
}; | |
items.pushIfNotExist(val, function(e) { | |
return e === val; | |
}); | |
}, | |
"remove": function (val) { | |
indx = items.indexOf(val); | |
if(indx!=-1) items.splice(indx, 1); | |
}, | |
"clear": function() { | |
items = null; | |
}, | |
"items": function() { | |
return items; | |
} | |
} | |
} | |
var chklist = new checkboxes(); | |
$('#checkall').on('click', function(e){ | |
var all_checkboxes = $('input:checkbox'); | |
all_checkboxes.each(function() { | |
if($(this).is(':visible') && !$(this).prop('checked')) { | |
$(this).prop('checked','checked'); | |
chklist.addUnique($(this).val()); | |
$(this).parent().prepend('<span>'+chklist.items().length+'. </span>'); | |
} | |
}); | |
}); | |
$('#uncheckall').on('click', function(e){ | |
var all_checkboxes = $('input:checkbox'); | |
all_checkboxes.each(function() { | |
if($(this).is(':visible') && $(this).prop('checked')) { | |
$(this).prop('checked', false); | |
$(this).parent().find('span').remove(); | |
} | |
}); | |
chklist.clear(); | |
chklist = new checkboxes(); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment