How can I require the user to confirm a button click?

Use this board to ask questions or have discussions with other Rich Displays users.
Post Reply
kevinh
Profound User
Posts: 43
Joined: Tue May 19, 2009 4:31 pm
First Name: Kevin
Last Name: Hunter
Company Name: Integrated Corporate Solutions
Phone: 2567608239
Address 1: 501 S Wood Ave
City: Florence
State / Province: Alabama
Zip / Postal Code: 35630
Country: United States
Location: Florence Alabama
Contact:

How can I require the user to confirm a button click?

Post by kevinh »

When a user clicks a button I want an alert type window (or some type of interaction) to appear requiring the user to confirm that they meant to click the button. Confirming would result in the button's action to continue, canceling would just act like the button was never clicked.
I know I could handle within the program but in this case I need a solution without having to return to the program.

I found there is a javascript function that I see can be used like:

Code: Select all

onclick="return confirm('Click OK to Close the Page, Click Cancel to Return to the Page');"
When I try to set either the onclick property of the button or the onsubmit property of the record format with

Code: Select all

return confirm('Click OK to Close the Page, Click Cancel to Return to the Page')
I get an error that
'return' statement outside of function
If I take out the "return" then I get the alert window but clicking OK or Cancel has no impact, nothing happens when the alert window closes.

When I try to set the button's onclick property as below nothing happens when I click the button, no alert window, the button's action doesn't occur.

Code: Select all

js: function confirmClose() {
return confirm('Click OK to Close the Page, Click Cancel to Return to the Page');
}
I'm not sure if I need to be doing something with that function.

Is there a PUI way of requiring a confirmation for an onclick event that would do what I need?
Scott Klement
Experienced User
Posts: 2711
Joined: Wed Aug 01, 2012 8:58 am
First Name: Scott
Last Name: Klement
Company Name: Profound Logic
City: Milwaukee
State / Province: Wisconsin

Re: How can I require the user to confirm a button click?

Post by Scott Klement »

If I understand correctly, I'd code it so that it either submits the screen (you can do this from within your onclick by calling the pui.click() API) or does not if the user hits cancel. Right?

If so you'd code your onclick like this:

Code: Select all

var result = confirm('Click OK to Close the Page, Click Cancel to Return to the Page');
if (result) pui.click();
The 'result' variable is a boolean variable that will be true if OK was clicked, and false if CANCEL was clicked. So if they hit OK, I do a pui.click() to submit control back to the RPG program. If cancel is clicked, I do nothing, leaving them on the active screen as before.

Note: If you use the 'onclick' event, you should make sure you do NOT have a field bound to the 'response' property of your button. You should only use one or the other (onclick or response) never both.
kevinh
Profound User
Posts: 43
Joined: Tue May 19, 2009 4:31 pm
First Name: Kevin
Last Name: Hunter
Company Name: Integrated Corporate Solutions
Phone: 2567608239
Address 1: 501 S Wood Ave
City: Florence
State / Province: Alabama
Zip / Postal Code: 35630
Country: United States
Location: Florence Alabama
Contact:

Re: How can I require the user to confirm a button click?

Post by kevinh »

Scott,
That does exactly what I needed. Thanks!
Post Reply

Who is online

Users browsing this forum: Bing [Bot] and 1 guest