Search code examples
web2pypydal

How to change the location of the checkbox labels in SQLform


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.

Form with checkbox labels


Solution

  • Thank you Tim for your answer. That told me everything I needed to know. Here is what I had to do:

    1. Find the relevant function in the gluon\sqlhtml.py. For me it was formstyle_bootstrap4_inline_factory

    2. Copy the _inner function which is in the formstyle_boostrap4_inline_factory function into my application and rename it formstyle_myapp (putting it in a model file is probably the easiest)

    3. Copy the add_class function from gluon.sqlhtml and add it into formstyle_myapp function. This makes it visible to formstyle_myapp only.

    4. Change the default formstyle setting in db.py to point to the new function: response.formstyle = formstyle_myapp

    5. 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:

       elif controls['_type'] == 'checkbox' or controls['_type'] == 'radio':
           _controls = DIV(controls, _class="%s" % col_class)