When used with buttons as follows, SQL form misses the offset causing the
buttons misplaced towards left (see buttons-misaligned.png file).
buttons = [
TAG.button(T('Save'),_type="submit",_value="save",_class="btn
btn-primary"),
TAG.button(T('Cancel'),_type="button", _class="btn btn-cancel
pull-right",_onClick = "parent.location='%s' " % URL('index'))
]
form = SQLFORM(db.person, buttons= buttons)
As a workaround, inside gluon/sqlhtml.py file I modified the following line
_controls = DIV(controls, _help, _class=col_class)
with
_controls = DIV(controls, _help, _class="%s %s" %
(offset_class, col_class))
Then the form looks as expected (see "buttons-aligned.png" file). I am not
sure whether my fix has any side-effects though.
As a reference this is the whole function:
def formstyle_bootstrap3_inline_factory(col_label_size=3):
""" bootstrap 3 horizontal form layout
Note:
Experimental!
"""
def _inner(form, fields):
form.add_class('form-horizontal')
label_col_class = "col-sm-%d" % col_label_size
col_class = "col-sm-%d" % (12 - col_label_size)
offset_class = "col-sm-offset-%d" % col_label_size
parent = CAT()
for id, label, controls, help in fields:
# wrappers
_help = SPAN(help, _class='help-block')
# embed _help into _controls
# SALIH changed the following line
# _controls = DIV(controls, _help, _class=col_class)
_controls = DIV(controls, _help, _class="%s %s" %
(offset_class, col_class))
if isinstance(controls, INPUT):
if controls['_type'] == 'submit':
controls.add_class('btn btn-primary')
_controls = DIV(controls, _class="%s %s" % (col_class,
offset_class))
if controls['_type'] == 'button':
controls.add_class('btn btn-default')
elif controls['_type'] == 'file':
controls.add_class('input-file')
elif controls['_type'] in ('text', 'password'):
controls.add_class('form-control')
elif controls['_type'] == 'checkbox':
label['_for'] = None
label.insert(0, controls)
_controls = DIV(DIV(label, _help, _class="checkbox"),
_class="%s %s" % (offset_class,
col_class))
label = ''
elif isinstance(controls, (SELECT, TEXTAREA)):
controls.add_class('form-control')
elif isinstance(controls, SPAN):
_controls = P(controls.components,
_class="form-control-static %s" % col_class)
elif isinstance(controls, UL):
for e in controls.elements("input"):
e.add_class('form-control')
elif controls is None or isinstance(controls, basestring):
_controls = P(controls, _class="form-control-static %s" %
col_class)
if isinstance(label, LABEL):
label['_class'] =
add_class(label.get('_class'),'control-label %s' % label_col_class)
parent.append(DIV(label, _controls, _class='form-group',
_id=id))
return parent
return _inner
I wanted to share it and your feedback from fellow developers.
--
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.