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 [email protected].
For more options, visit https://groups.google.com/d/optout.

Reply via email to