Groups keyboard shortcuts have been updated
Dismiss
See shortcuts

Using ImageButton() as submit throws an error

4 views
Skip to first unread message

Seth

unread,
Jul 20, 2009, 8:20:43 PM7/20/09
to TurboGears
When I try to use ImageButton() as my submit for a form, it throws the
error: The input field 'x' was not expected

Here's my code:

class SubmitForm(TableForm):
class fields(WidgetsList):
body = TextArea(default='Enter text here...', rows=2, cols=30)
submit = ImageButton(src='/images/share_button.png')

Changing ImageButton() to SubmitButton() makes the form submit fine.

What am I doing wrong? I'm not finding any special settings needed for
ImageButton() in the docs.

Thanks,
Seth

Diez B. Roggisch

unread,
Jul 21, 2009, 3:02:00 AM7/21/09
to turbo...@googlegroups.com
Seth schrieb:

image-buttons submit the x and y coordinate of the pixel the user
pressed. You need to add x and y as parameters to your controller -
which the error-message indicates (well, it indicates the x, and you'd
get a similar error with y once the x is added...)

Diez

Seth

unread,
Jul 21, 2009, 2:05:08 PM7/21/09
to TurboGears
Diez,

Is this documented anywhere? It'd be nice to see a tutorial or
something.

The error message is a form error, not a controller error. Adding x
and y parameters to the controller (per your instructions) doesn't
seem to work. However, if I set x & y to a HiddenField() in the form
class it does seem to submit correctly.

Is specifying x and y as a HiddenField() the recommended setting with
ImageButton()?

Thanks for your help. Sorry about the newbie questions. I'm still
looking for good documentation on tw.forms & formencode (the docs I've
been able to find thus far are scant at best).

Seth

percious

unread,
Jul 21, 2009, 3:55:14 PM7/21/09
to TurboGears
Here are the docs for the image button:

http://toscawidgets.org/documentation/tw.forms/modules/fields/buttons.html#tw.forms.fields.ImageButton

unfortunately they don't describe the use of x/y. I think that you
have to realize that this is part of the HTTP spec, and therefore the
developer must have an understanding of how image buttons in general
would work with TG, whether or not they are inside a widget. I will
think about where would be the correct place to include this
documentation.

In tw2, we will have controller methods available for each widget,
which means we can provide a code example for each widget that is
documented.

cheers.
-chris

Diez B. Roggisch

unread,
Jul 22, 2009, 4:56:05 AM7/22/09
to turbo...@googlegroups.com, Seth
On Tuesday 21 July 2009 20:05:08 Seth wrote:
> Diez,
>
> Is this documented anywhere? It'd be nice to see a tutorial or
> something.

That's the way HTML works, it's not specific to TG.

> The error message is a form error, not a controller error. Adding x
> and y parameters to the controller (per your instructions) doesn't
> seem to work. However, if I set x & y to a HiddenField() in the form
> class it does seem to submit correctly.
>
> Is specifying x and y as a HiddenField() the recommended setting with
> ImageButton()?

Ah, sorry, yes, setting them as hidden fields is ok. But you'd still need
them on the controller then.

We added a middleware that just strips them from the request before they get
processed, because we never use them.

Diez

Seth

unread,
Aug 25, 2009, 8:23:50 PM8/25/09
to TurboGears
Diez,

I've been successfully using the HiddenField method, but being as we
have no need for the x/y either I was wondering if you'd be so kind as
to post the code you're using to strip out x/y. I haven't seemed to be
able to find any help anywhere else with this.

Thanks,
Seth

Diez B. Roggisch

unread,
Aug 26, 2009, 6:23:20 AM8/26/09
to turbo...@googlegroups.com
On Wednesday 26 August 2009 02:23:50 Seth wrote:
> Diez,
>
> I've been successfully using the HiddenField method, but being as we
> have no need for the x/y either I was wondering if you'd be so kind as
> to post the code you're using to strip out x/y. I haven't seemed to be
> able to find any help anywhere else with this.

http://paste.turbogears.org/paste/104758

Diez

Reply all
Reply to author
Forward
0 new messages