Item13026: BUTTON onclick="confirm(...)" does not abort on Cancel

pencil
Priority: Normal
Current State: No Action Required
Released In: n/a
Target Release:
Applies To: Extension
Component: JQueryPlugin
Branches:
Reported By: FlorianSchlichting
Waiting For:
Last Change By: MichaelDaum
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
 

ItemTemplate edit

Summary BUTTON onclick="confirm(...)" does not abort on Cancel
ReportedBy FlorianSchlichting
Codebase trunk
SVN Range
AppliesTo Extension
Component JQueryPlugin
Priority Normal
CurrentState No Action Required
WaitingFor
Checkins
ReleasedIn n/a
CheckinsOnBranches
trunkCheckins
masterCheckins
ItemBranchCheckins
Release02x01Checkins
Release02x00Checkins
Release01x01Checkins
Topic revision: r3 - 12 Jun 2018, MichaelDaum
The copyright of the content on this website is held by the contributing authors, except where stated elsewhere. See Copyright Statement. Creative Commons License    Legal Imprint    Privacy Policy