Reputation: 27
In my appconfig.ini
file the default formstyle
is bootstrap3_inline
. But when the form is displayed in the browser, the form elements are shown vertically, one below the other, and the page-source says the form class is form-horizontal
. I tried using all the other options for formstyle
, but could not get the bootstrap form-inline
. I am using Chrome browser.
I want to have the 'form-inline' style because my form has only a few elements, and a lot of screen space is unused with the 'form-horizontal' style. How do I get the form to be displayed in one line?
Upvotes: 0
Views: 313
Reputation: 25536
The bootstrap3_inline
name is somewhat misleading, as it is really intended to produce a Bootstrap horizontal form. The term "inline" in this context is just intended to mean that each form field displays the label and the input inline (as opposed to the default, with the input displayed below the label).
To convert to a true Bootstrap inline form, you can simply change the class of the FORM
object after it has been constructed:
form = SQLFORM(db.mytable).process()
form['_class'] = 'form-inline'
If you want to apply this style to multiple forms or make it the default, you can create a custom formstyle
function based on the boostrap3_inline
formstyle:
from gluon.sqlhtml import formstyle_bootstrap3_inline_factory
def inline_form(form, fields):
form = formstyle_bootstrap3_inline_factory(3)(form, fields)
form['_class'] = 'form-inline'
return form
Then you can apply this style to a single form:
form = SQLFORM(db.mytable, formstyle=inline_form)
Or make it the default formstyle
:
response.formstyle = inline_form
Upvotes: 1