Side navigation
#11002 closed feature (patchwelcome)
Opened December 12, 2011 05:22PM UTC
Closed June 26, 2012 01:32PM UTC
Last modified July 19, 2012 04:49PM UTC
Add serializeObject method to core
Reported by: | ajpiano | Owned by: | |
---|---|---|---|
Priority: | undecided | Milestone: | None |
Component: | unfiled | Version: | 1.7.1 |
Keywords: | 1.8-discuss | Cc: | |
Blocked by: | Blocking: |
Description
It's probably more useful into have a method in core for serializing a form directly to an object, instead of an array of objects with name and value keys. Luckily, Ben Alman has a very small implementation that leverages the existence of serializeArray to give us just such a method.
My experience tells me this is a relatively common use-case: I've used it on a number of projects, and I've directed numerous people toward it as well in the last year or two. Not only is it beneficial when developing single-page apps with Backbone or the like, it's considerably simpler than existing options (in core) for users who need to submit a form via ajax, but also want to augment the data with some properties beforehand.
https://raw.github.com/cowboy/jquery-misc/master/jquery.ba-serializeobject.js
While most plugins should stay just that - plugins - I think that this feature is common enough, lean enough, and low-level enough for us to be able to offer it in core.
Attachments (0)
Change History (18)
Changed December 12, 2011 05:22PM UTC by comment:1
keywords: | → 1.8-discuss |
---|
Changed December 13, 2011 02:48PM UTC by comment:2
description: | It's probably more useful into have a method in core for serializing a form directly to an object, instead of an array of objects with name and value keys. Luckily, Ben Alman has a very small implementation that leverages the existence of serializeArray to give us just such a method. \ \ My experience tells me this is a relatively common use-case: I've used it on a number of projects, and I've directed numerous people toward it as well in the last year or two. Not only is it beneficial when developing single-page apps with Backbone or the like, it's considerably simpler than existing options (in core) for users who need to submit a form via ajax, but also want to augment the data with some properties beforehand. \ \ https://raw.github.com/cowboy/jquery-misc/master/jquery.ba-serializeobject.js \ \ While most plugins should stay just that - plugins - I think that this feature is common enough, lean enough, and low-level enough for us to be able to offer it in core. \ \ → It's probably more useful into have a method in core for serializing a form directly to an object, instead of an array of objects with name and value keys. Luckily, Ben Alman has a very small implementation that leverages the existence of serializeArray to give us just such a method.\ \ My experience tells me this is a relatively common use-case: I've used it on a number of projects, and I've directed numerous people toward it as well in the last year or two. Not only is it beneficial when developing single-page apps with Backbone or the like, it's considerably simpler than existing options (in core) for users who need to submit a form via ajax, but also want to augment the data with some properties beforehand. \ \ https://raw.github.com/cowboy/jquery-misc/master/jquery.ba-serializeobject.js\ \ While most plugins should stay just that - plugins - I think that this feature is common enough, lean enough, and low-level enough for us to be able to offer it in core.\ \ |
---|
+1
Changed December 13, 2011 04:29PM UTC by comment:3
+0
Changed December 13, 2011 05:21PM UTC by comment:4
description: | It's probably more useful into have a method in core for serializing a form directly to an object, instead of an array of objects with name and value keys. Luckily, Ben Alman has a very small implementation that leverages the existence of serializeArray to give us just such a method.\ \ My experience tells me this is a relatively common use-case: I've used it on a number of projects, and I've directed numerous people toward it as well in the last year or two. Not only is it beneficial when developing single-page apps with Backbone or the like, it's considerably simpler than existing options (in core) for users who need to submit a form via ajax, but also want to augment the data with some properties beforehand. \ \ https://raw.github.com/cowboy/jquery-misc/master/jquery.ba-serializeobject.js\ \ While most plugins should stay just that - plugins - I think that this feature is common enough, lean enough, and low-level enough for us to be able to offer it in core.\ \ → It's probably more useful into have a method in core for serializing a form directly to an object, instead of an array of objects with name and value keys. Luckily, Ben Alman has a very small implementation that leverages the existence of serializeArray to give us just such a method. \ \ My experience tells me this is a relatively common use-case: I've used it on a number of projects, and I've directed numerous people toward it as well in the last year or two. Not only is it beneficial when developing single-page apps with Backbone or the like, it's considerably simpler than existing options (in core) for users who need to submit a form via ajax, but also want to augment the data with some properties beforehand. \ \ https://raw.github.com/cowboy/jquery-misc/master/jquery.ba-serializeobject.js \ \ While most plugins should stay just that - plugins - I think that this feature is common enough, lean enough, and low-level enough for us to be able to offer it in core. \ \ |
---|
+1, Okay okay you convinced me. Somewhat of a side note, do we need a general method to convert arrays to hashes? I haven't looked at the code to see how often we do that.
Changed December 14, 2011 03:36AM UTC by comment:5
status: | new → open |
---|
Changed December 14, 2011 04:15PM UTC by comment:6
description: | It's probably more useful into have a method in core for serializing a form directly to an object, instead of an array of objects with name and value keys. Luckily, Ben Alman has a very small implementation that leverages the existence of serializeArray to give us just such a method. \ \ My experience tells me this is a relatively common use-case: I've used it on a number of projects, and I've directed numerous people toward it as well in the last year or two. Not only is it beneficial when developing single-page apps with Backbone or the like, it's considerably simpler than existing options (in core) for users who need to submit a form via ajax, but also want to augment the data with some properties beforehand. \ \ https://raw.github.com/cowboy/jquery-misc/master/jquery.ba-serializeobject.js \ \ While most plugins should stay just that - plugins - I think that this feature is common enough, lean enough, and low-level enough for us to be able to offer it in core. \ \ → It's probably more useful into have a method in core for serializing a form directly to an object, instead of an array of objects with name and value keys. Luckily, Ben Alman has a very small implementation that leverages the existence of serializeArray to give us just such a method.\ \ My experience tells me this is a relatively common use-case: I've used it on a number of projects, and I've directed numerous people toward it as well in the last year or two. Not only is it beneficial when developing single-page apps with Backbone or the like, it's considerably simpler than existing options (in core) for users who need to submit a form via ajax, but also want to augment the data with some properties beforehand. \ \ https://raw.github.com/cowboy/jquery-misc/master/jquery.ba-serializeobject.js\ \ While most plugins should stay just that - plugins - I think that this feature is common enough, lean enough, and low-level enough for us to be able to offer it in core.\ \ |
---|
+0, I don't really see this getting used without the presence of some other plugin.
Changed December 15, 2011 07:28AM UTC by comment:7
+1
Changed December 19, 2011 05:36PM UTC by comment:8
description: | It's probably more useful into have a method in core for serializing a form directly to an object, instead of an array of objects with name and value keys. Luckily, Ben Alman has a very small implementation that leverages the existence of serializeArray to give us just such a method.\ \ My experience tells me this is a relatively common use-case: I've used it on a number of projects, and I've directed numerous people toward it as well in the last year or two. Not only is it beneficial when developing single-page apps with Backbone or the like, it's considerably simpler than existing options (in core) for users who need to submit a form via ajax, but also want to augment the data with some properties beforehand. \ \ https://raw.github.com/cowboy/jquery-misc/master/jquery.ba-serializeobject.js\ \ While most plugins should stay just that - plugins - I think that this feature is common enough, lean enough, and low-level enough for us to be able to offer it in core.\ \ → It's probably more useful into have a method in core for serializing a form directly to an object, instead of an array of objects with name and value keys. Luckily, Ben Alman has a very small implementation that leverages the existence of serializeArray to give us just such a method. \ \ My experience tells me this is a relatively common use-case: I've used it on a number of projects, and I've directed numerous people toward it as well in the last year or two. Not only is it beneficial when developing single-page apps with Backbone or the like, it's considerably simpler than existing options (in core) for users who need to submit a form via ajax, but also want to augment the data with some properties beforehand. \ \ https://raw.github.com/cowboy/jquery-misc/master/jquery.ba-serializeobject.js \ \ While most plugins should stay just that - plugins - I think that this feature is common enough, lean enough, and low-level enough for us to be able to offer it in core. \ \ |
---|
+1
Changed December 20, 2011 09:17PM UTC by comment:9
Keep in mind that the logic in my $.fn.serializeObject
plugin is rather naive, and will only create the most basic objects. See this fiddle to get a better idea of what I'm talking about:
http://jsfiddle.net/cowboy/Qxc72/
If you want to do this "right"—ie. less feature requests than you're currently getting—one of two things probably has to happen:
1) a much more powerful form parser will need to be created, and with it an updated $.param
serializer
2) a $.deparam
compliment to the existing $.param
(surprise, surprise, another plugin of mine)
or, of course, a third alternative:
3) "wontfix"
I'm more than happy to work with you guys to help make this happen, or to at least help explain what's really involved if I haven't made it clear enough.
Let me know!
Changed December 20, 2011 09:29PM UTC by comment:10
@cowboy: I think we're interested in seeing an implementation. It's hard to say whether it will make it into core without first seeing its impact on the code.
Changed December 20, 2011 11:37PM UTC by comment:11
If this is going to get a lot bigger to handle more cases, I'm likely to move my +1 to a -1. However, the effort wouldn't be wasted if the outcome was a solid plugin.
Changed January 25, 2012 10:26PM UTC by comment:12
+10. The other two serialize methods are useless to me.
Changed February 09, 2012 05:44PM UTC by comment:13
#11312 is a duplicate of this ticket.
Changed February 09, 2012 06:07PM UTC by comment:14
The duplicate above was mine, so thought I'd suggest on this thread allowing passing a parameter "string", "array" or "object" to the serialize() method (defaulting to "string") rather than adding new methods
Changed April 05, 2012 02:13AM UTC by comment:15
Just use the code from the fiddle above: https://raw.github.com/cowboy/jquery-misc/master/jquery.ba-serializeobject.js
This is too small to really be put into a plugin. If it turns into some larger function, then discuss taking it out and putting it back into a plugin. But, honestly, I don't really see that happening.
Changed June 02, 2012 03:13PM UTC by comment:16
@cowboy is saying (and I agree) that the simple implementation in the OP would probably not be robust enough, and we'd get bugs filed against its shortcomings. So before we land it I think we'd need to see what a complete implementation looks like. First we need an owner.
Changed June 26, 2012 01:32PM UTC by comment:17
resolution: | → patchwelcome |
---|---|
status: | open → closed |
Still open to an implementation here, with the caveat that we don't want a large amount of code. If it's a lot, it should be a plugin.
Changed July 19, 2012 04:49PM UTC by comment:18
_comment0: | Just as a starting point: http://jsfiddle.net/DxC5J/2/ \ \ Checkboxes do not seem to return a useful value. → 1342716775973664 |
---|
Just as a starting point: http://jsfiddle.net/DxC5J/3/
Checkboxes do not seem to return a useful value.