Is there an easy way to reposition the labels for checkboxes? I would like to show them on the left side in the same way as the other controls.
How to change the location of the checkbox labels in SQLform
84 Views Asked by Andrew At
2
There are 2 best solutions below
0

You just need to make your own formstyle (copying formstyle_bootstrap3_inline_factory, which I'm guessing you're using)
Then cut out the rule treating checkboxes differently:
elif controls['_type'] == 'checkbox':
label['_for'] = None
label.insert(0, controls)
label.insert(1, ' ')
_controls = DIV(DIV(label, _help, _class="checkbox"),
_class="%s %s" % (offset_class, col_class))
label = ''
Thank you Tim for your answer. That told me everything I needed to know. Here is what I had to do:
Find the relevant function in the
gluon\sqlhtml.py
. For me it wasformstyle_bootstrap4_inline_factory
Copy the
_inner
function which is in theformstyle_boostrap4_inline_factory
function into my application and rename itformstyle_myapp
(putting it in a model file is probably the easiest)Copy the
add_class
function fromgluon.sqlhtml
and add it intoformstyle_myapp
function. This makes it visible toformstyle_myapp
only.Change the default
formstyle
setting in db.py to point to the new function:response.formstyle = formstyle_myapp
Finally, adjust the checkbox part of the
formstyle_myapp
to position the label on the left under all the other labels and the checkbox to the right under all the the other controls: