Great tip.

I did something similar, but in views.
I wrote a function to take a form and break it into a giver number of
columns using bootstrap grid classes.
The default stacked layout gets pretty boring with time.

2017-04-26 18:18 GMT-03:00 Alfonso Serra <aleonse...@gmail.com>:

> This is great i have found a way to have full control on how a form is
> displayed and behave other than writing mystyle(form) in a view.
>
> This is how it would look like:
> def stylefrm(self):
>     #create any custom header or form.custom.begin
>     frm = FORM(_class="myform")
>
>     #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
>
>         #implement keepvalues
>         if self.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 button
>     frm.append(INPUT(_type="submit", _value="submit"))
>
>     return str(frm)
>
> # replace web2py html serialization for your own
> SQLFORM.xml = stylefrm
>
> def index():
>     frm = SQLFORM.factory(
>         Field("name", "string")
>         , Field("quantity", "integer")
>         , Field("price", "double")
>     )
>     # remove SQLFORM factory auto id field
>     frm.fields.pop(0)
>
>     result = "Not submitted"
>
>     if frm.process(keepvalues=True).accepted:
>         result = "All good"
>     elif frm.errors:
>         result = "Not good"
>
>     return locals()
>
> View:
> {{=frm}}
> {{=result}}
>
> --
> 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 web2py+unsubscr...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.
>



-- 


Carlos J. Costa
Cientista da Computação  | BS Computer Science
Esp. Gestão em Telecom   | PgC Telecom Mangement
<º))><

-- 
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 web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to