Priority: Normal
Current State: No Action Required
Released In: n/a
Target Release:
The first example for the use of BUTTON is
%BUTTON{
"%MAKETEXT{"Submit"}%"
onclick="confirm('Are your sure?')"
}%
and clicking on the button creates a popup with "OK" and "Cancel" options. Contrary to what one might expect, these do not have different consequences, e.g. if there's a
target
specified, clicking "Cancel" will not abort but take you to target.
Ideally, BUTTON has a little bit of logic to detect that and abort unless OK was selected, for example
var ask=confirm('Are you sure?')
if (ask) {
window.location.href='$target'
} else {
return false
}
At the very least, the example should be extended to prevent unexpected behaviour.
--
FlorianSchlichting - 11 Sep 2014
If an
onclick
handler is specified will the normal
target
be ignored, no matter what you decide on the confirm dialog. That's because the system adds a
return false
to the onclick handler.
If the button is of type
submit
will an onclick handler be performed before the actual submit handler is executed. Both have no connection to each other.
In both cases will you have to code the effect of a confirm dialog yourself:
%BUTTON{
"Submit"
onclick="if (confirm('Are your sure?')) {window.location.href='some target'}"
}%
or
<form id="myform">
<input type="hidden" name="decision" value="yes" />
%BUTTON{
"Submit"
onclick="if (confirm('Are your sure?')) {jQuery('#myform').submit()}"
}%
</form>
--
MichaelDaum - 12 Jun 2018