need help with FORM.confirm

276 views
Skip to first unread message

Viator

unread,
Mar 3, 2016, 2:23:53 AM3/3/16
to web2py-users

Hello!

I use a SQLFORM to enter client data which works perfectly.
The problem: when adding a new record I want the user to confirm that some of the entered data is also entered into a second database table but I cant' get the confirmation dialog to run.


The recommended way 

form = FORM.confirm("Are you shure?")
if form.accepted:


does not work at all. No matter where in the controller I place the code.
The dialog simply does not pop up and never enters the if form.accepted clause. Looking at the pages source does not show up any javascript containing "Are you shure".

Adding a field of class='delete', will popup a dialog when checking the field, but the text shown is not what I nedd.

I spend ages on google to find an working example but i failed.

I'm working on Debian 8, browser is cromium, javascript is enabled, popups are as well.

Any help is very welcome, Thank you,

Thorsten

Anthony

unread,
Mar 3, 2016, 10:01:53 AM3/3/16
to web2py-users
Have you put the form in your view somewhere via {{=form}}?

Note, it doesn't generate a pop-up, just a standard form.

Anthony

Viator

unread,
Mar 4, 2016, 4:20:20 AM3/4/16
to web...@googlegroups.com


Am Donnerstag, 3. März 2016 16:01:53 UTC+1 schrieb Anthony:
Have you put the form in your view somewhere via {{=form}}?

Note, it doesn't generate a pop-up, just a standard form.

Anthony

Hi Anthony!

Thank you for your help.

I'm afraid I don't understand you completly. I have a form, which is in the view and which is displayd. I can enter values and the values are stored in the db. So far it works fine.
Additionally I want to aks the user if he wants to add some of the added data to another table when the user clicks on "save".
As far as I understood, this can be done using form.confirm which will pop up a dialog.

The code (as far as I understand it should work):

def client_create():
    db
.ck_client.default = request.args(0)
    form
= SQLFORM(db.ck_client, keepvalues=True)
    form
.add_button('Cancel', URL('clients'))

    if form.process().accepted:

         form_confirm = form.confirm("Do you want to add this to other table?", hidden=False)
        # FORM.confirm(.... does not work either
# neither does it if I remove the hidden=False parameter         if form_confirm.accepted:
            # add to another table

           
db.my_table.insert(enabled='True',
                             
direction='INCOMING',
                             
description=form.vars.description,
                             
client_id=form.vars.id,
                              )

        response
.flash = 'form accepted'
        redirect(URL('clients'))
   
elif form.errors:
        response
.flash = 'form has errors'
    return locals()

I don't know if I do not understand how form.confirm should work, if I miss something or if this is a bug and, as mentioned, I could not find any working example for this. Only massimos hint to:

form = FORM.confirm('Are you sure?')
if form.accepted: do_what_needs_to_be_done()

which doesn't help me any further.



Thank you for helping me, Thorsten
 

Anthony

unread,
Mar 4, 2016, 6:21:35 AM3/4/16
to web2py-users
I think you misunderstand the confirmation form functionality. FORM.confirm is a static method of the FORM class, so calling it on an existing form object will do nothing to that form -- it will instead return a completely new form (so, you might as well just call FORM.confirm rather than form.confirm on your existing form). Because it creates a whole new form, you must explicitly show the new form in your view. However, it looks like you don't really want this -- instead, you want a dialog to pop up when the user attempts to submit an existing SQLFORM. web2py does not include built-in functionality to do what you want -- you will have to handle that via Javascript on the client.

Another option would simply be to include a boolean field in the main form (e.g., checkbox or switch widget) asking if the data should be added to the other table. Then check for that flag in the controller and proceed accordingly. See http://web2py.com/books/default/chapter/29/07/forms-and-validators#Adding-extra-form-elements-to-SQLFORM.

Anthony

Viator

unread,
Mar 4, 2016, 8:24:17 AM3/4/16
to web...@googlegroups.com
Hello!

Thank you, Anthony. This helped me a lot. I will go and add some JS to the page.

Again, thank you, Thorsten
Reply all
Reply to author
Forward
0 new messages