Skip to main content

Bug Tracker

Side navigation

#12264 closed feature (wontfix)

Opened August 11, 2012 11:08AM UTC

Closed October 29, 2012 05:28PM UTC

Allow users customize the return obj in the serializeArray

Reported by: terry@poloniouslive.com 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};
});
Attachments (0)
Change History (9)

Changed August 11, 2012 11:18AM UTC by terry@poloniouslive.com comment:1

Changed August 13, 2012 03:40PM UTC by timmywil comment:2

component: unfiledajax
keywords: → 1.9-discuss
priority: undecidedlow
status: newopen
version: → 1.8.0

Changed September 09, 2012 01:10AM UTC by dmethvin comment:3

type: enhancementfeature

Bulk change from enhancement to feature.

Changed September 27, 2012 01:26PM UTC by gibson042 comment:4

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

Changed October 14, 2012 10:37PM UTC by mikesherov comment:5

-1

Changed October 14, 2012 11:44PM UTC by rwaldron comment:6

-1, Monkey patch it

Changed October 22, 2012 05:19PM UTC by gibson042 comment:7

-1

Changed October 22, 2012 05:44PM UTC by gnarf comment:8

-1,

 .find( ":input" ).map(...) 
anyone?

Changed October 29, 2012 05:28PM UTC by mikesherov comment:9

resolution: → wontfix
status: openclosed