Modify ↓
Ticket #12264 (closed feature: wontfix)
Allow users customize the return obj in the serializeArray
| Reported by: | terry@… | Owned by: | |
|---|---|---|---|
| Priority: | low | Milestone: | None |
| Component: | ajax | Version: | 1.8.0 |
| Keywords: | 1.9-discuss | Cc: | |
| Blocking: | Blocked by: |
Description
I propose to accept a callback function in the serializeArray, so that the users can customize or filter the returning object.
For example:
$('#form').serializeArray(function(elem,val){
return {label:elem.name, value:val, type:elem.type};
});
This produces the following data structure:
[{label: "a", value: "1", type: "text"},
{label: "b", value: "2", type: "text"},
{label: "c", value: "3", type: "hidden"},
....]
Or more powerful one:
$('#form').serializeArray(function(elem,val){
var $elem = jQuery(elem);
if($elem.hasClass('invalid')){
return null;
}
else if($elem.is(':date')){
return {name:elem.name, value: mySpecialDateFormat(val)};
}
else if($elem.is(':hidden')){
mySpecialMethodToHandleHiddenInput(elem.name, val);
}
return {name:elem.name, value:val};
});
Change History
comment:2 Changed 9 months ago by timmywil
- Keywords 1.9-discuss added
- Priority changed from undecided to low
- Status changed from new to open
- Component changed from unfiled to ajax
- Version set to 1.8.0
Please follow the bug reporting guidlines and use jsFiddle when providing test cases and demonstrations instead of pasting the code in the ticket.
Note: See
TracTickets for help on using
tickets.

relevant pull request: https://github.com/jquery/jquery/pull/891