Hi Jaime,
Could you copy and past all your definition of def bootstrap3(form, fields)
> ?
>
This is my bootstrap3 function.
def bootstrap3(form, fields):
parent = FIELDSET()
for id, label, controls, help in fields:
if not help:
_help = ''
else:
# wrappers
_help = SPAN(help, _class='help-block')
# embed _help into _controls
if isinstance(controls, basestring) or isinstance(controls, int):
_controls = DIV(P(controls, _help,
_class='form-control-static'))
elif isinstance(controls, TEXTAREA):
_controls = DIV(controls, _help)
else:
_controls = DIV(controls, _help)
# submit unflag by default
_submit = False
if isinstance(controls, INPUT):
if controls['_type'] not in ['file', 'checkbox', 'radio']:
controls.add_class('form-control')
if controls['_type'] == 'submit':
# flag submit button
_submit = True
controls['_class'] = 'btn btn-primary'
# For password fields, which are wrapped in a CAT object.
if isinstance(controls, CAT) and isinstance(controls[0], INPUT):
controls[0].add_class('form-control')
elif isinstance(controls, SELECT):
controls.add_class('form-control')
elif isinstance(controls, TEXTAREA):
controls.add_class('form-control')
if _submit:
# submit button has unwrapped label and controls, different
class
parent.append(DIV(label, controls, _id=id))
# unflag submit (possible side effect)
_submit = False
else:
# unwrapped label
parent.append(DIV(label, _controls, _class='form-group',
_id=id))
return parent
To style the radio buttons and check boxes I use the following functions.
def bs3radiowidget(field, value, **attributes):
if isinstance(value, (list,tuple)):
value = str(value[0])
else:
value = str(value)
attr = OptionsWidget._attributes(field, {}, **attributes)
attr['_class'] = attr.get('_class', 'web2py_radiowidget')
requires = field.requires
if not isinstance(requires, (list, tuple)):
requires = [requires]
if requires:
if hasattr(requires[0], 'options'):
options = requires[0].options()
else:
raise SyntaxError('widget cannot determine options of %s'
% field)
options = [(k, v) for k, v in options if str(v)]
opts = []
for k, v in options:
checked = {'_checked': 'checked'} if k == value else {}
opts.append(DIV(LABEL(v, INPUT(_type='radio',
_id='%s%s' % (field.name, k),
_name=field.name,
requires=attr.get('requires', None),
hideerror=True, _value=k,
value=value,
**checked),
_for='%s%s' % (field.name, k)), _class='radio'))
return TAG[''](*opts, **attr)
def bs3checkboxeswidget(field, value, **attributes):
if isinstance(value, (list, tuple)):
values = [str(v) for v in value]
else:
values = [str(value)]
attr = OptionsWidget._attributes(field, {}, **attributes)
attr['_class'] = attr.get('_class', 'web2py_checkboxeswidget')
requires = field.requires
if not isinstance(requires, (list, tuple)):
requires = [requires]
if requires and hasattr(requires[0], 'options'):
options = requires[0].options()
else:
raise SyntaxError('widget cannot determine options of %s'
% field)
options = [(k, v) for k, v in options if k != '']
opts = []
for k, v in options:
if k in values:
r_value = k
else:
r_value = []
opts.append(DIV(LABEL(v, INPUT(_type='checkbox',
_id='%s%s' % (field.name, k),
_name=field.name,
requires=attr.get('requires', None),
hideerror=True, _value=k,
value=r_value),
_for='%s%s' % (field.name, k)), _class="checkbox"))
if opts:
opts.append(
INPUT(requires=attr.get('requires', None),
_style="display:none;",
_disabled="disabled",
_name=field.name,
hideerror=False))
opts=DIV(opts)
return TAG[''](*opts, **attr)
Hope this helps you solve the issue.
Kind regards,
Annet
--
Resources:
- http://web2py.com
- http://web2py.com/book (Documentation)
- http://github.com/web2py/web2py (Source code)
- https://code.google.com/p/web2py/issues/list (Report Issues)
---
You received this message because you are subscribed to the Google Groups
"web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
For more options, visit https://groups.google.com/d/optout.