Opened 10 years ago
Closed 10 years ago
#12264 closed feature (wontfix)
Allow users customize the return obj in the serializeArray
Reported by: | Owned by: | ||
---|---|---|---|
Priority: | low | Milestone: | None |
Component: | ajax | Version: | 1.8.0 |
Keywords: | 1.9-discuss | Cc: | |
Blocked by: | Blocking: |
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 (9)
comment:1 Changed 10 years ago by
comment:2 Changed 10 years ago by
Component: | unfiled → ajax |
---|---|
Keywords: | 1.9-discuss added |
Priority: | undecided → low |
Status: | new → open |
Version: | → 1.8.0 |
comment:3 Changed 10 years ago by
Type: | enhancement → feature |
---|
Bulk change from enhancement to feature.
comment:9 Changed 10 years ago by
Resolution: | → wontfix |
---|---|
Status: | open → closed |
Note: See
TracTickets for help on using
tickets.
relevant pull request: https://github.com/jquery/jquery/pull/891