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
80 Views Asked by Andrew At
2
There are 2 best solutions below
0
On
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_factoryCopy the
_innerfunction which is in theformstyle_boostrap4_inline_factoryfunction into my application and rename itformstyle_myapp(putting it in a model file is probably the easiest)Copy the
add_classfunction fromgluon.sqlhtmland add it intoformstyle_myappfunction. This makes it visible toformstyle_myapponly.Change the default
formstylesetting in db.py to point to the new function:response.formstyle = formstyle_myappFinally, adjust the checkbox part of the
formstyle_myappto position the label on the left under all the other labels and the checkbox to the right under all the the other controls: