How do I track checkboxes that are not onscreen?
How do I track checkboxes that are not onscreen?
totallyplandom
Posts: 27Questions: 1Answers: 1
Hi All,
I'm having a problem. Basically i'm incorporating Datatables in a submission FORM where I have a list of users to whom I wish to send an email. Although DT remembers the checkboxes when I "unfilter" the list to redisplay all items, if the list is in a filtered state (and I'm guessing paginated) it doesn't SUBMIT the values that aren't currently onscreen.
What am I missing?
Best.
I'm having a problem. Basically i'm incorporating Datatables in a submission FORM where I have a list of users to whom I wish to send an email. Although DT remembers the checkboxes when I "unfilter" the list to redisplay all items, if the list is in a filtered state (and I'm guessing paginated) it doesn't SUBMIT the values that aren't currently onscreen.
What am I missing?
Best.
This discussion has been closed.
Replies
[code]
$('#example input[type=checkbox]').live('click', function () {
var newIds = [];
$('#example input[type=checkbox]:checked').each(function() {
newIds.push( this.id );
});
$('#SelIds').val( newIds );
});
[/code]
That reads all the checked check boxes and then pushes them into an array. If you unchecked a box, when that function runs it skips that unchecked box. This is why I run the function on every checkbox click. It clears and then rebuilds the entire array using only the checked check boxes.
There may be a better way but this works for me.
It could still be done by setting and comparing different arrays in different states... but as I said there is probably a better way.
http://jsfiddle.net/isaacs2/C8qd7/
[code]
$('form').bind('submit', function(e) {
var rows = dataTable.fnGetNodes(),
inputs = [];
// Add the inputs which are not currently visible to the form
for ( var i = 0, len = rows.length; i < len; i++) {
var $fields = $(rows[i]).find('input[name]:hidden:checked');
$fields.each(function (idx, el) {
inputs.push('');
});
}
$(this).append( inputs.join('') );
});
[/code]
Best.