SQLFORM.grid and oncreate error

15 views
Skip to first unread message

Scott Hunter

unread,
Dec 2, 2016, 11:17:57 PM12/2/16
to web2py-users
If the oncreate callback for a SQLFORM.grid sets form.errors to true, the record is not created; similarly, if form.errors.<fieldname> is set to an error message.

However, shouldn't the form for adding the record return, and in the latter case, with the specified fields showing their error messages?  In my case, the list comes up instead.

Here is my form & callback although there isn't much to them:

    def add_handler(form):
        if form.vars.f_Member_ID=='':
            form.errors.f_Member_ID = "ID required"
            session.flash = "ID required"
            return
    session.flash = "Handler added"

    form=SQLFORM.grid( db.t_member.f_User==t.f_User, args=request.args[:2], csv=False, 
        searchable=True, deletable=False, details=False, editable=False, 
        oncreate=add_handler,
        fields=[db.t_member.f_Member_ID, db.t_member.f_FirstName, db.t_member.f_LastName] )

- Scott

Scott Hunter

unread,
Dec 3, 2016, 8:25:13 AM12/3/16
to web2py-users
My bad; I was using concrete (the callback for AFTER a record has been created) instead of onvalidation (the one for BEFORE that).
Reply all
Reply to author
Forward
0 new messages