I loop through a form object to change all the classes:
form = crud.create(db.messages, next = URL('index'))
parts = ['title', 'body', 'subject'] # corresponding fields
classes = 'form-control col-md-12' # my classes
for p in parts:
form.custom.widget[p]['_class'] = '%s %s' % (classes, form.custom.widget[p]['_type'])
This is working - but: subject
is an autocomplete widget:
db.messages.subject.widget = SQLFORM.widgets.autocomplete(...)
and here _class
is not changed (or altered afterwards again?)
How can this be fixed? Thanks!
The autocomplete widget is a
TAG
object that contains two components, the first of which is theINPUT
element. So, do something like:Note, you can use the
add_class
method to add classes to an element that has an existing class.Also, instead of manually changing all the classes, you might see if setting
crud.settings.formstyle
to "bootstrap3_stacked" or "bootstrap3_inline" works for you. If not, you can also write a custom formstyle function to generate the exact form layout you want.