[Catalyst] jQuery gotcha

2010-01-31 Thread S.A. Kiehn
Found a change in the latest jQuery (1.4.1) from the previous release I used 
(1.3.2) that affected  a Catalyst app of mine.  Regarding form field 
submissions, jQuery now submits multiple checkbox (or select) values with the 
variable name followed by the array [] brackets (probably to appease PHP).  I 
had a problem with a previous working app and used firebug to look at my JSON 
post and found the brackets.

What used to be:

    tags  25
    tags  18
    tags  10

is now:

    tags[]  25
    tags[]  18
    tags[]  10

Changing:

    my $tags = $c-request-params-{tags};

to:

    my $tags = $c-request-params-{'tags[]'};

corrected it (the quotes are needed).  Hope this is helpful.

This was my first post, been reading forums for awhile and want to thank all of 
you for the skill and knowledge you offer.  I thank you for the forum posts, 
blogs, calendars and books.  I am not a trained programmer, but with your help 
I have been able to build a few production Catalyst apps.

Thanks,
Scott K.




  ___
List: Catalyst@lists.scsys.co.uk
Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst
Searchable archive: http://www.mail-archive.com/catalyst@lists.scsys.co.uk/
Dev site: http://dev.catalyst.perl.org/


Re: [Catalyst] jQuery gotcha

2010-01-31 Thread Charlie Garrison

Good afternoon,

On 31/01/10 at 8:13 PM -0800, S.A. Kiehn keenli...@ymail.com wrote:

Found a change in the latest jQuery (1.4.1) from the previous 
release I used (1.3.2) that affected  a Catalyst app of mine.  
Regarding form field submissions, jQuery now submits multiple 
checkbox (or select) values with the variable name followed by 
the array [] brackets (probably to appease PHP).  I had a 
problem with a previous working app and used firebug to look at 
my JSON post and found the brackets.


In some of the info about the new version, they talk about the 
new feature:


http://jquery14.com/day-01

Nested param serialization (jQuery.param() Documentation, 
Commit 1, Commit 2)


jQuery 1.4 adds support for nested param serialization in 
jQuery.param, using the approach popularized by PHP, and 
supported by Ruby on Rails. For instance, {foo: [bar, baz]} 
will be serialized as “foo[]=barfoo[]=baz”.


In jQuery 1.3, {foo: [bar, baz]} was serialized as 
“foo=barfoo=baz”. However, there was no way to encode a 
single-element Array using this approach. If you need the old 
behavior, you can turn it back on by setting the traditional 
Ajax setting (globally via jQuery.ajaxSettings.traditional or on 
a case-by-case basis via the traditional flag).


So rather than changing the name of params you use, change the 
behaviour of jQuery instead:


http://api.jquery.com/jQuery.param/

jQuery.ajaxSettings.traditional = true;

Note, I haven't tried the above yet. But I think that's because 
MyApp uses Params::Nested which effectively normalizes the param 
names for $c-req, so the extra brackets haven't been an issue.


In either case, I had forgotten about that factoid in the 
release docco; thanks for the notice.



Charlie

--
   Ꮚ Charlie Garrison ♊ garri...@zeta.org.au
   〠 PO Box 141, Windsor, NSW 2756, Australia

O ascii ribbon campaign - stop html mail - www.asciiribbon.org
http://www.ietf.org/rfc/rfc1855.txt

___
List: Catalyst@lists.scsys.co.uk
Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst
Searchable archive: http://www.mail-archive.com/catalyst@lists.scsys.co.uk/
Dev site: http://dev.catalyst.perl.org/