How to change the position of submit button in a SQLFORM

648 views
Skip to first unread message

Dominique

unread,
Nov 14, 2011, 5:26:20 AM11/14/11
to web...@googlegroups.com
Hello All,

I have a form built with SQLFORM.factory.

I would like to change the position of the submit button.

I know how to insert an element somewhere with for instance form[0][3][1].insert(-1, my_element) but not how to move the submit button from its pre-defined place (last row) to another place.

I'd prefer not to define its place in the view but rather in the controller.

For info, the hierarchy of the form is:
form
input1
select1
div1
div2
div class="w2p_fl"
div class="w2p_fw"
select id='bla1"
select id="bla2"
div class="w2p_fc"
div3 id="submit_record_row"
iv class="w2p_fl"
div class="w2p_fw"
input type="submit"
div class="w2p_fc"

I'd like to move the submit button (which is in the div3) to the div2, just after the select id="bla2"

Thanks in advance for any help

Dominique

DenesL

unread,
Nov 14, 2011, 8:53:30 AM11/14/11
to web2py-users
Hi Dominique,

I believe the easiest would be to manually insert the submit button at
the appropriate location, as in the following example:

form = SQLFORM.factory(
Field('name'),
Field('age','integer'),
formstyle='divs',
buttons=[],
)
form[0].insert(1,DIV(INPUT(_type='submit', _value='submit me')))

Notes:
- the submit button will be in the middle of the form in this case
- you can further style the DIV or the INPUT as needed
- formstyle divs used here, it should work with the others too
- buttons=[] blocks the auto-created submit button at the bottom
- change the insert index to your desired location

Anthony

unread,
Nov 14, 2011, 9:05:11 AM11/14/11
to web...@googlegroups.com
On Monday, November 14, 2011 8:53:30 AM UTC-5, DenesL wrote:
- buttons=[] blocks the auto-created submit button at the bottom

Another undocumented feature. What is the purpose of 'buttons'? The only code I see that deals with it simply checks whether it includes 'submit'. What happens if you put other things in the list? If it's just for including/excluding the submit button, why not a boolean?

Anthony 

Massimo Di Pierro

unread,
Nov 14, 2011, 9:34:30 AM11/14/11
to web2py-users
You can add other buttons like

buttons = [INPUT(_type="submit"),
INPUT(_type="button",_onclick="history.go(-1);return False")]

etc.

Anthony

unread,
Nov 14, 2011, 10:20:58 AM11/14/11
to web...@googlegroups.com
On Monday, November 14, 2011 9:34:30 AM UTC-5, Massimo Di Pierro wrote:
You can add other buttons like

buttons = [INPUT(_type="submit"),
INPUT(_type="button",_onclick="history.go(-1);return False")]

Can you show a complete example? I just tried the above with SQLFORM and SQLFORM.factory, and it shows neither of the buttons listed above. I also can't find any code that references the 'buttons' argument, except for:

        if (not readonly) and ('submit' in buttons):
            widget = INPUT(_type='submit',
                           _value=submit_button)
            xfields.append(('submit_record'+SQLFORM.ID_ROW_SUFFIX,
                            '', widget,col3.get('submit_button', '')))
            self.custom.submit = widget

Anthony

Dominique

unread,
Nov 14, 2011, 2:23:39 PM11/14/11
to web...@googlegroups.com
Hi,

Thanks DenesL, Anthony and Massimo for your help.
I appreciate.
That works fine !
Thanks a lot

Dominique
Reply all
Reply to author
Forward
0 new messages