Page 1 of 1

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

Posted: Fri May 31, 2013 12:36 pm
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?

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

Posted: Fri May 31, 2013 1:03 pm
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.

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

Posted: Fri May 31, 2013 3:05 pm
by kevinh
Scott,
That does exactly what I needed. Thanks!