serialize() missing data?
serialize() missing data?
ktambascio
Posts: 1Questions: 0Answers: 0
Hi,
I have a data table form that lists out around 150 items, each row having an check box to select the item. In addition, each row has a link to a jQuery dialog that pops up that allows the user to select from a series of sub items. Each subitem choice has a check box to select the subitem. The jQuery dialog is only shown when the user clicks a link for the item.
By default, the two newest subitems are selected. If I deselect one of them, then the serialize() function does not include the checked subitem. If I leave the checked check boxes alone, they do show up in the array.
This is the first time I've tried to use a pop-up window to manipulate some form data, so it's very possible that I'm doing something wrong.
Here's the javascript code doing the selection:
[code]
jQuery('#form').submit( function() {
var sData = jQuery('.item_checkbox', itemTable.fnGetNodes()).serialize();
jQuery('#selected_items').attr('value', sData);
var sData = jQuery('.subitem_checkbox', itemTable.fnGetNodes()).serialize();
jQuery('#selected_subitems').attr('value', sData);
} );
itemTable = jQuery('#items').dataTable( {
"sPaginationType": "full_numbers"
} );
[/code]
The checkbox for the item have a class of "item_checkbox", and the the subitems have a class of "subitem_checkbox". I'm trying to put them into two hidden fields to make the item/subitem parsing on the server easier.
I thought at first this was a server-side issue, but using firebug, I can see that the serialize() function return data is missing the data I would expect to see there. I'll try to look at the serialize() code myself, but I don't know how far I'll get.
Thanks,
Kevin
I have a data table form that lists out around 150 items, each row having an check box to select the item. In addition, each row has a link to a jQuery dialog that pops up that allows the user to select from a series of sub items. Each subitem choice has a check box to select the subitem. The jQuery dialog is only shown when the user clicks a link for the item.
By default, the two newest subitems are selected. If I deselect one of them, then the serialize() function does not include the checked subitem. If I leave the checked check boxes alone, they do show up in the array.
This is the first time I've tried to use a pop-up window to manipulate some form data, so it's very possible that I'm doing something wrong.
Here's the javascript code doing the selection:
[code]
jQuery('#form').submit( function() {
var sData = jQuery('.item_checkbox', itemTable.fnGetNodes()).serialize();
jQuery('#selected_items').attr('value', sData);
var sData = jQuery('.subitem_checkbox', itemTable.fnGetNodes()).serialize();
jQuery('#selected_subitems').attr('value', sData);
} );
itemTable = jQuery('#items').dataTable( {
"sPaginationType": "full_numbers"
} );
[/code]
The checkbox for the item have a class of "item_checkbox", and the the subitems have a class of "subitem_checkbox". I'm trying to put them into two hidden fields to make the item/subitem parsing on the server easier.
I thought at first this was a server-side issue, but using firebug, I can see that the serialize() function return data is missing the data I would expect to see there. I'll try to look at the serialize() code myself, but I don't know how far I'll get.
Thanks,
Kevin
This discussion has been closed.
Replies
I don't see anything immediately obvious in your code (other than declaring sData twice :-) ) - using fnGetNodes is the right thing to do in this case. If you just do something like:
[code]
console.log( itemTable.fnGetNodes().length );
console.log( jQuery('.item_checkbox', itemTable.fnGetNodes()).length );
[/code]
in your submit handler (return false to cancel the form submission) do they give the lengths that you would expect - i.e. the number of rows in the table for the first line, and the number of "item_checkbox" classes elements in the table for the second one.
Regards,
Allan