Before i drive you crazy, i have commented the function SQLFORM.createform
so i could implement my own form styles just passing the SQLFORM instance
to a function like:
def renderform(self):
style = self.formstyle
return str(self.formstyles[style](self))
response.formstyle = "default"
SQLFORM.formstyles['default'] = frm_default_style
SQLFORM.formstyles['rows'] = frm_table_style
SQLFORM.xml = renderform
self.components werent created and i guess thats why default fields were
messed up.
To fix all this and be able to create my own styles with absolute freedom,
this worked, sqlhml.py line 1402:
def createform(self, xfields):
formstyle = self.formstyles["ul"]
# if isinstance(formstyle, basestring):
# if formstyle in SQLFORM.formstyles:
# formstyle = SQLFORM.formstyles[formstyle]
# else:
# raise RuntimeError('formstyle not found')
if callable(formstyle):
try:
table = formstyle(self, xfields)
for id, a, b, c in xfields:
self.field_parent[id] = getattr(b, 'parent', None) \
if isinstance(b, XmlComponent) else None
Trick the SQLFORM to always use a light representation, just so
field.default gets populated properly, and then hack it with the .xml()
trick above
That way im able to represent the form however i like with full self aware
state, with a custom function like:
def frm_default_style(self):
#create any custom header
frm = FORM(_class="myform")
keepvalues = self.keepvalues if hasattr(self, "keepvalues") else False
#iterate over the fields and create any behaviour and style you like
for fld in self.fields:
field = self.table[fld] #access the SQLFORM to inspect field
properties
#implemented keepvalues
if keepvalues:
out = LABEL(fld, _for=fld) + INPUT(_name=fld, requires=field.
requires, _value=self.vars[fld])
else:
out = LABEL(fld, _for=fld) + INPUT(_name=fld, requires=field.
requires)
frm.append(out)
# add the hidden fields + token
frm.append(self.hidden_fields())
#add any submit
frm.append(INPUT(_type="submit", _value="submit"))
return frm
At the controller:
frm2 = SQLFORM(db.agencies, formstyle="rows").process(formname="agencies")
--
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.