Bug Tracker

Modify

Ticket #12264 (closed feature: wontfix)

Opened 10 months ago

Last modified 7 months ago

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:1 Changed 10 months ago by terry@…

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

comment:3 Changed 9 months ago by dmethvin

  • Type changed from enhancement to feature

Bulk change from enhancement to feature.

comment:4 Changed 8 months ago by gibson042

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

comment:5 Changed 7 months ago by mikesherov

-1

comment:6 Changed 7 months ago by rwaldron

-1, Monkey patch it

comment:7 Changed 7 months ago by gibson042

-1

comment:8 Changed 7 months ago by gnarf

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

comment:9 Changed 7 months ago by mikesherov

  • Status changed from open to closed
  • Resolution set to wontfix

Please follow the  bug reporting guidlines and use  jsFiddle when providing test cases and demonstrations instead of pasting the code in the ticket.

View

Add a comment

Modify Ticket

Action
as closed
Author


E-mail address and user name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.