remoteFormRequest is not nice about checkbox fields

0 views
Skip to first unread message

gldn...@gmail.com

unread,
May 24, 2006, 12:08:49 PM5/24/06
to TurboGears Trunk
Working out of the 1.0 branch...

In the turbogears/widgets/static/ajax.js, remoteFormRequest does not
play nicely with submitting values from CheckBoxList widgets.

The problem is, all of the checkboxes have the same name. It looks
like line 9 might be the biggest source of the problem, and in general
the use of a dictionary (or whatever it's called in JS, I'm not a JS
guru myself).

Say I have a form with this Checkbox widget:

CheckBoxList(name='foo', options=[(1, 'One'), (2, 'Two'), (3,
'Three')])

The controller is decorated with:

@expose(fragment=True)
@validate(validators=dict(foo=validators.Set()))
def process(self, foo=None):
print foo
# ...

When the RemoteForm containing the CheckBoxList widget is submitted, it
uses the remoteFormRequest JS function to do so.

Let's say you clicked 1 and 2.

What you get back in foo in the process method of the controller is
['3']. After peeking under the hood using Firebug (wonderful Firefox
extension!!) it is actually submitting this as the POST data:

foo=3&tg_random=1148485489989

This is because remoteFormRequest just looks at the fact that it's an
INPUT tag, gets the name, gets the value, and stuffs it into a
dictionary.

What it should probably do is see that it's an INPUT tag, see that it's
of the "checkbox" type, then see if "checked" is set or not. If it is,
it should add the name/value pair to a list, rather than a dictionary.
When it hands it off to remoteRequest, remoteRequest in turn passes it
to queryString.

I may have my terminology all wrong but I am going to charge forward
and see if I can get a patch ready for remoteFormRequest that will do
what I need it to do. I'll post it here when I'm done.

Matthew Scott

unread,
May 24, 2006, 1:27:12 PM5/24/06
to TurboGears Trunk
On 5/24/06, gldn...@gmail.com <gldn...@gmail.com> wrote:
In the turbogears/widgets/static/ajax.js, remoteFormRequest does not
play nicely with submitting values from CheckBoxList widgets.
 
[ ... ]

I may have my terminology all wrong but I am going to charge forward
and see if I can get a patch ready for remoteFormRequest that will do
what I need it to do.  I'll post it here when I'm done.

As promised, diff is attached. Again, this is against the latest rev of the 1.0 branch as of this posting.


--
Matthew R. Scott
remoteFormRequest-checkbox-support.diff

Matthew Scott

unread,
May 24, 2006, 2:08:02 PM5/24/06
to TurboGears Trunk
Updated patch is attached...  There was a bug when I tried it with a form that had a SELECT element in it.  This newest patch is slightly better, but could probably be cleaned up a tiny bit more.  Have a deadline that I had to meet, so this will do for me, for now :)

Comments more than welcome! :)
--
Matthew R. Scott
remoteFormRequest-checkbox-support-2.diff

gldn...@gmail.com

unread,
Jun 1, 2006, 1:43:14 PM6/1/06
to TurboGears Trunk
Matthew Scott wrote:
> Updated patch is attached... There was a bug when I tried it with a form
> that had a SELECT element in it. This newest patch is slightly better, but
> could probably be cleaned up a tiny bit more. Have a deadline that I had to
> meet, so this will do for me, for now :)

This has been posted as
http://trac.turbogears.org/turbogears/ticket/905 as per a suggestion
off-list.

Kevin -- any idea if this will make it into the next egg-ified release?

Thanks,
Matthew

Reply all
Reply to author
Forward
0 new messages