Bug 35012: Prevent Click handler firing twice

test plan:
a) build a new basket + order line using "item create on placing an order"
b) in the item creation dialog (neworderempty.pl) please use the webbrowsers dev tools to analyze the [...] button next to subfield d (Date acquired) and inspect the events that get fired by clicking
c) notice the Clicktag_952_subfield_d_* event gets fired twice.
d) apply patch and reload page
e) there should be only 1 click handler left (besides the jquery one), which points to the Clicktag_952_subfield_* function

Signed-off-by: Marcel de Rooy <m.de.rooy@rijksmuseum.nl>
See also bug 35298. You may have seen that the Focus event of dateaccessioned
did not fire. But that is related to use of Flatpickr in this plugin.
Signed-off-by: Katrin Fischer <katrin.fischer.83@web.de>
Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io>
This commit is contained in:
Jan Kissig 2023-10-10 13:36:04 +02:00 committed by Tomas Cohen Arazi
parent e2821c7962
commit ec3fe5d41e
Signed by: tomascohen
GPG key ID: 0A272EA1B2F3C15F

View file

@ -329,7 +329,15 @@ sub _add_binding {
#click event applies to buttonDot
if( $pars =~ /^(e|ev|event)$/i ) { # new style event handler assumed
$bind= qq| \$("#$ctl").$ev(\{id: '$id'\}, $fname);\n|;
if ($ev eq "click"){
# remove already registered click listeners
$bind= qq| \$("#$ctl").off('click');\n|;
$bind.= qq| \$("#$ctl").$ev(\{id: '$id'\}, $fname);\n|;
} else {
$bind= qq| \$("#$ctl").$ev(\{id: '$id'\}, $fname);\n|;
}
$script='';
} elsif( $fname eq 'noclick' ) { # no click: return false, no scroll
$bind= qq| \$("#$ctl").$ev(function () { return false; });\n|;