timsavage / django-ajax-forms

Automatically exported from code.google.com/p/django-ajax-forms
Other
1 stars 1 forks source link

Form instances with a prefix set produce ajax data incompatible with jQuery library #9

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?
1. create a Form subclass, MyForm, with fields "name" and "email"
2. call ajax_forms.utils.form_to_json(MyFormClass())
3. call ajax_forms.utils.form_to_json(MyFormClass(prefix='special'))

What is the expected output? What do you see instead?

For 1, the ajax field names should be "name" and "email" and that is what
happens.

For 2, the ajax field names should be "special-name" and "special-email",
instead, they are exactly like 1, "name" and "email".  This creates a
problem when the jQuery extension searches for a selector
$(':input[name=..., it's looking for the name of the field attribute when
django has output the name of the field attribute prefixed by the value of
the "prefix" keyword.  Long story short, it break s 

What version of the product are you using? On what operating system?

Revision 31 on Ubuntu 8.10

Please provide any additional information below.

I've attached a patch to fix this by using the html_name attribute of a
bound form as the key for a given field's validation data in
ajax_forms.utils.form_to_json .  The maintainer might also consider a
further enhancement of using the auto_id attribute of a form instance as
the jQuery selector for finding a given input field on the page, this would
require some more small adjustment in the form_to_json method as well.

Original issue reported on code.google.com by wiley.kestner on 13 Mar 2009 at 2:05

Attachments:

GoogleCodeExporter commented 9 years ago
Yikes, I looked over the patch I just submitted and realized I'd only done 
things
halfway.  Here's a better patch.

Original comment by wiley.kestner on 13 Mar 2009 at 2:34

Attachments:

GoogleCodeExporter commented 9 years ago
You are correct the expected output in the second case should include the 
prefix.

Original comment by Sle...@gmail.com on 15 Mar 2009 at 2:20

GoogleCodeExporter commented 9 years ago
Any thoughts about the patch?  I'm in #django channel now if you want to chat

Original comment by wiley.kestner on 15 Mar 2009 at 2:22

GoogleCodeExporter commented 9 years ago

Original comment by Sle...@gmail.com on 15 Mar 2009 at 2:22

GoogleCodeExporter commented 9 years ago
I have just taken a look at the patch(s)

The updates in the first patch are good and will work well, but the second set 
have a
problem with the html_name variable, it will contain stale data.  

Original comment by Sle...@gmail.com on 15 Mar 2009 at 2:36

GoogleCodeExporter commented 9 years ago
I've had a dig around in django's form code and I have a solution.

Original comment by Sle...@gmail.com on 15 Mar 2009 at 2:46

GoogleCodeExporter commented 9 years ago
Fix has been committed in revision 41.

Made use of the forms add_prefix method. A small hack was required to support
`equal_to_field` rule. A better solution will require investigation if there 
are more
rules that require another form field as a parameter.

Original comment by Sle...@gmail.com on 15 Mar 2009 at 3:09