Bug Tracker

Opened 7 years ago

Closed 6 years ago

#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:
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 7 years ago by terry@…

comment:2 Changed 7 years ago by timmywil

Component: unfiledajax
Keywords: 1.9-discuss added
Priority: undecidedlow
Status: newopen
Version: 1.8.0

comment:3 Changed 6 years ago by dmethvin

Type: enhancementfeature

Bulk change from enhancement to feature.

comment:4 Changed 6 years ago by gibson042

-1, this seems much better suited to a plugin.

comment:5 Changed 6 years ago by mikesherov

-1

comment:6 Changed 6 years ago by Rick Waldron

-1, Monkey patch it

comment:7 Changed 6 years ago by gibson042

-1

comment:8 Changed 6 years ago by gnarf

-1, .find( ":input" ).map(...) anyone?

comment:9 Changed 6 years ago by mikesherov

Resolution: wontfix
Status: openclosed
Note: See TracTickets for help on using tickets.