Identical form params to post

39 views
Skip to first unread message

Todd Willey

unread,
Sep 22, 2009, 1:34:26 PM9/22/09
to sam...@googlegroups.com
I have a form that I can add and remove fields from dynamically. I
end up with multiple parameters of the same name, like:
tag[]=foo
tag[]=bar

But in my post action, params only has the last one (tag[]=bar). Is
there a workaround to post all of those? It seems unclean to have to
run $('#myform').serializeArray() since I'm already getting the params
in the post callback.

-todd[1]

--
CONFIDENTIALITY NOTICE: This email is for sole use of intended
recipient(s). Unauthorized use is prohibited.

Aaron Quint

unread,
Sep 22, 2009, 2:28:54 PM9/22/09
to sam...@googlegroups.com
Hey Todd

Interesting - this might actually be a bug in Sammy. Internally, we
collect the values of any non-submit input and place them in the
params object with name=value. This case, though, there are multiple
values per-name. I actually submitted a patch that with the help of a
couple other devs, recently got submitted to jQuery core to fix
jQuery.param() to make it work with nested fields like you seem to
have in your form. I'll have to check on where its at and if it will
be part of jQuery 1.3.3.

In the meantime, would it work for you to have those fields get
serialized as an Array?
--AQ

Aaron Quint
http://www.quirkey.com

Todd Willey

unread,
Sep 23, 2009, 1:20:37 AM9/23/09
to sam...@googlegroups.com
On Tue, Sep 22, 2009 at 2:28 PM, Aaron Quint <aa...@quirkey.com> wrote:
>
> Hey Todd
>
> Interesting - this might actually be a bug in Sammy. Internally, we
> collect the values of any non-submit input and place them in the
> params object with name=value. This case, though, there are multiple
> values per-name. I actually submitted a patch that with the help of a
> couple other devs, recently got submitted to jQuery core to fix
> jQuery.param() to make it work with nested fields like you seem to
> have in your form. I'll have to check on where its at and if it will
> be part of jQuery 1.3.3.
>
> In the meantime, would it work for you to have those fields get
> serialized as an Array?

I'm passing them straight through to the second argument of $.get, so
I just need something compatible. For now I'm using
$('#myform').serialize() and ignoring the params altogether.

In the future it might be nice to decide within the callback how to
handle params, especially given that $.load(...) will change between a
get and post based on the type of the params argument. If I had a
params object that could do params.serialize() and
params.serializeArray() on to cover both cases, that would be boss.
Especially if params['my_thing'] still worked as it does now. Of
course with serializeArray() the same problem would likely arise in
the case of same-named fields, but in general it might be nice.

Thanks for responding. I'm looking forward to the next release.

-todd[1]
Reply all
Reply to author
Forward
0 new messages