On Monday, August 12, 2013 7:07:14 AM UTC-7, Michael Beller wrote:
>
> Update ...
>
> I found one problem: when I was dynamically adding form fields as html 
> elements, I wasn't adding them as field objects to the form object on the 
> postback so w2p didn't know about the fields for validation.
>
> But I still must be confused how components work.  I load the form but the 
> submit action reloads the entire page and therefore does not process the 
> form.  What am I missing? ...
>
>
Is it the accept?  (See below.) 

 

> Action:
>
> def send_msg():
>     return dict()
>
>
> View:
>
> {{extend 'layout.html'}}
> <div id="send_msg_form">
>     {{=LOAD('sendmsg','get_msg_vars',ajax=True)}}
> </div>
>
>
> Component:
>
> def get_msg_vars():
>     fields = []
>     fields.append(db.msg.msg_typ)
>     if request.vars['msg_typ']:
>         db.msg.msg_typ.default = request.vars['msg_typ']
>         msg_typ = db.msg_typ(request.vars['msg_typ'])
>         for var in msg_typ.msg_typ_vars:
>             msg_typ_var_lbl = ' '.join(x.capitalize() for x in 
> var.split('_'))
>             fields.append(Field(var, label=msg_typ_var_lbl, 
> requires=IS_NOT_EMPTY()))
>     form=SQLFORM.factory(*fields)
>     mt = form.element(_name='msg_typ')
>     mt['_onchange'] = XML("ajax('get_msg_vars', ['msg_typ'], 
> 'send_msg_form');")
>     if form.accepts(request,session):
>
>
In the book (Chap 12, sec 12.1.1, pg 521), the example uses "if 
form.process().accepted:"
I've seen reference here in the group to that being *the new and approved 
coding style* for form processing.

        response.flash="form accepted"
>     elif form.errors:
>         response.flash="form is invalid"
>     else:
>         response.flash="please fill the form"
>     return form
>
>  

/dps
 

-- 
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/groups/opt_out.

Reply via email to