@Robin,
I propose I change and I already implemented in in trunk.
onvalidation instead of onaccept. In this way
1) we do not need modify T2
2) works for both SQLFORM and FORM
3) onvalidate can be passed a lambda form:... that can add multi-field
validation too
def f(form):
if form.vars.a!=form.vars.b:
form.errors.a='must be same as b'
form.errors.b='must be same as a'
if form.accepts(....,onvalidation=lambda form: f(form))
Please give it a try.
Massimo
On Jan 9, 9:04 pm, mdipierro <[email protected]> wrote:
> In trunk. See if it works as you suggested.
>
> massimo
>
> On Jan 9, 6:29 pm, mdipierro <[email protected]> wrote:
>
> > ok. I will change accept, we ca change T2 too. T2 does not need to
> > keep backward compatibility. We can discuss this on Monday on the IRC.
> > Thanks Robin.
>
> > Massimo
>
> > On Jan 9, 6:13 pm, Robin B <[email protected]> wrote:
>
> > > t2.create() already has onaccept= (it should have been called
> > > onsave= ) because it does not get called until after the record has
> > > been created/updated within the form. You are right oncreate/onupdate
> > > could be replaced with onsave, which does not need to be passed to the
> > > SQLFORM.
>
> > > Ideally, it should work like this:
>
> > > class T2(...):
> > > def create(...,onsave=..., onaccept=...)
> > > form = SQLFORM()
> > > if form.accepts(...,onaccept=onaccept):
> > > if onsave: onsave(form)
> > > self.redirect(next=...)
>
> > > So to summarize, t2 create/update both need onsave/onaccept, and
> > > SQLFORM needs onaccept.
>
> > > Robin
>
> > > On Jan 9, 5:43 pm, mdipierro <[email protected]> wrote:
>
> > > > I can see the use for onaccept but why oncreate/onupdate. This would
> > > > be equivalent to putting the code after accepts(..) returns. Am I
> > > > missing something?
>
> > > > Massimo
>
> > > > On Jan 9, 3:33 pm, Robin B <[email protected]> wrote:
>
> > > > > SQLFORM.accepts(...) could use hooks: onaccept, oncreate, onupdate.
>
> > > > > onaccept: called after FORM.accept and immediately before create() or
> > > > > insert()
> > > > > oncreate: called after create()
> > > > > onupdate: callled after update()
>
> > > > > These hooks could be used by t2 and passed to SQLFORM:
> > > > > t2.update(onaccept=...,onupdate=...)
> > > > > t2.create(onaccept=...,oncreate=...)
>
> > > > > The important difference is that onaccept must be called after accept
> > > > > passes, but before the record is updated/inserted, so the user can
> > > > > modify attributes (set stamps, set incremental ids, etc) before saving
> > > > > the record.
>
> > > > > For t2 to properly support onaccept= is must be supported by SQLFORM.
>
> > > > > Thoughts?
>
> > > > > Robin
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"web2py Web Framework" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/web2py?hl=en
-~----------~----~----~----~------~----~------~--~---