Buttons In A Form

5,675 views
Skip to first unread message

Bruce Coble

unread,
Mar 13, 2012, 3:08:18 AM3/13/12
to toscawidge...@googlegroups.com
Hi all,

A form, by default, will add a submit button with the label "Save" at the bottom of a form. I am trying to add additional buttons next to the Save button (eg, a Reset button), but explicitly adding another button in the child class of my form class will render this new button among the form fields, & not next to the default Save button.

If I try to override the default Save button by explicitly adding a Save button & a Reset button within the child class of my form class, the Reset button is rendered with the form fields & the Save button is again rendered at the bottom of the form.

So my question is this: is there a preferred method of adding buttons to a form that will render all of the buttons in one place on the page (preferably at the bottom)?

Cheers,

Bruce

RJ Bean

unread,
Mar 13, 2012, 11:39:58 PM3/13/12
to toscawidgets-discuss
Hi Bruce,
This was not possible but Greg Jurman wrote it into tw2.forms here:

https://github.com/toscawidgets/tw2.forms/commit/94b471afc50999850b87f0af467e091e26ca42a1

It should be available in the 2.0.0 release coming soon.

-Ralph

Excerpts from Bruce Coble's message of Tue Mar 13 00:08:18 -0700 2012:

Bruce Coble

unread,
Mar 14, 2012, 12:59:16 AM3/14/12
to toscawidge...@googlegroups.com
Hi Greg & Ralph,

Thanks for the work on the buttons code. I just tested it out & it works a treat! This is how my test form ended up looking:

class TestForm(twf.FormPage):
    title = 'Test'
    class child(twf.TableForm):
        buttons = [twf.SubmitButton(id='submit', value='My Submit Button'),
                        twf.ResetButton(id='reset', value='My Reset Button', attrs = {'onclick': 'javascript:alert("Testing a JS alert")'})]
        id = twf.HiddenField()
        login = twf.TextField()
        password = twf.TextField() 

And with your new code Greg, the buttons appear at the bottom of the form in their own row, so they are nicely separate from the form fields.

Cheers,

Bruce

Greg Jurman

unread,
Mar 13, 2012, 5:25:17 PM3/13/12
to toscawidge...@googlegroups.com
Hi Bruce,

I've looked at the code form and this is pointing to a defect. I have opened a ticket here: https://github.com/toscawidgets/tw2.forms/issues/2

More info will become available when it is fixed as well as how to implement the change.


--
You received this message because you are subscribed to the Google Groups "ToscaWidgets-discuss" group.
To view this discussion on the web visit https://groups.google.com/d/msg/toscawidgets-discuss/-/808b-pOB1GEJ.
To post to this group, send email to toscawidge...@googlegroups.com.
To unsubscribe from this group, send email to toscawidgets-dis...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/toscawidgets-discuss?hl=en.


--
Greg Jurman
FOSS@RIT / Open Hardware Initiative

"A product will be late for a little while, but a product [that sucks] will suck forever." -Gabe Newell (VALVe) on Quality Control

Greg Jurman

unread,
Mar 13, 2012, 7:20:04 PM3/13/12
to toscawidge...@googlegroups.com
Hello again Bruce,

Form widget now has a `buttons` parameter that takes a list of buttons.

class TestForm(Form):
    buttons = [Button(value='Click here!'), SubmitButton(value='Submit')]

FYI: If you define a SubmitButton in `buttons` it WILL override the `submit` param.

merged commit here: https://github.com/toscawidgets/tw2.forms/commit/94b471afc50999850b87f0af467e091e26ca42a1

We will try and ship this out tonight on PyPI pending other commits.
Reply all
Reply to author
Forward
Message has been deleted
0 new messages