Hi
Using custom forms and trying to work with bootstrap three.
I'm using SQLFORM.grid() and then modifying the view using
form.custom.begin. The form tag in the html is still generated as:
<form method="post" enctype="multipart/form-data" class="web2py_form" action
="#">
instead of the form tag that is generated when you use SQLFORM.grid without
a custom view:
<form class="form-horizontal web2py_form col-md-7 col-lg-5 col-sm-9" method=
"post" enctype="multipart/form-data" action="#">
Here is the SQLFORM.grid() call:
grid = SQLFORM.grid(query, fields=fields,
orderby=orderby,
create=create, details=details,
editable=editable, deletable=deletable,
csv=False, search_widget=defaultSearch,
paginate=15, maxtextlength=45,
formname='userForm',
formstyle=my_formstyle, ui=grid_ui)
my_formstyle is:
def my_formstyle(form, fields):
col_sm_label_size = 4
col_md_label_size = 3
form.add_class('form-horizontal col-sm-9 col-md-7 col-lg-5')
label_col_class = "col-sm-%d col-md-%d" % (col_sm_label_size,
col_md_label_size)
col_class = "col-sm-%d col-md-%d" % ((12 - col_sm_label_size), (12 -
col_md_label_size))
offset_class = "col-sm-offset-%d col-md-offset-%s" % (col_sm_label_size,
col_md_label_size)
parent = CAT()
for id, label, controls, help in fields:
# wrappers
_help = SPAN(help, _class='help-block')
# embed _help into _controls
_controls = DIV(controls, _help, _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'] == 'text':
controls.add_class('form-control')
elif controls['_type'] == 'email':
controls.add_class('form-control')
elif controls['_type'] == '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):
controls.add_class('form-control')
elif isinstance(controls, TEXTAREA):
controls.add_class('form-control')
elif isinstance(controls, SPAN):
_controls = P(controls.components, _class="form-control-static
%s" % col_class)
if isinstance(label, LABEL):
label['_class'] = 'control-label %s' % label_col_class
parent.append(DIV(label, _controls, _class='form-group', _id=id))
return parent
and grid_ui is:
grid_ui = dict(widget='',
header='',
content='',
default='',
cornerall='',
cornertop='',
cornerbottom='',
button='btn btn-default button',
buttontext='buttontext button',
buttonadd='glyphicon glyphicon-plus space-after',
buttonback='glyphicon glyphicon-arrow-left space-after',
buttonexport='glyphicon glyphicon-download space-after',
buttondelete='glyphicon glyphicon-trash space-after',
buttonedit='glyphicon glyphicon-pencil space-after',
buttontable='glyphicon glyphicon-arrow-right space-after',
buttonview='glyphicon glyphicon-arrow-zoom-in space-after')
Any pointers on where to look to get the form.custom.begin to generate the
same form tag as SQLFORM.grid()?
-Jim
--
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.