[Koha-bugs] [Bug 30975] Framework plugins do not work on cloned fields/subfields

bugzilla-daemon at bugs.koha-community.org bugzilla-daemon at bugs.koha-community.org
Fri Feb 3 15:28:01 CET 2023


https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=30975

Julian Maurice <julian.maurice at biblibre.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
 Attachment #138318|0                           |1
        is obsolete|                            |

--- Comment #16 from Julian Maurice <julian.maurice at biblibre.com> ---
Created attachment 146146
  -->
https://bugs.koha-community.org/bugzilla3/attachment.cgi?id=146146&action=edit
Bug 30975: Fix framework plugins not working on cloned fields/subfields

Since bug 29155 (Upgrade jquery version to 3.6.0) framework plugins do
not work on a cloned field/subfield.
That is because we rely on jQuery's `.data('events')` to clone event
handlers to the cloned elements, and that was removed in jQuery 1.8.0
(I did not confirm but it's possible it continued to work after that
thanks to jQuery Migrate)

It is apparently still possible to access these event handlers by using
`jQuery._data(element, "events")` but here's what jQuery 1.8.0 release
notes says about it:
"this is not a supported public interface; the actual data structures
may change incompatibly from version to version."
So we should not rely on it.

Instead, what this patch does is use event delegation [1].
Events are bound to a parent container, so when elements are added
dynamically inside that container, we don't need to re-attach event
handlers manually

This patch also comes with a bit of cleanup, and introduce "breaking
changes" (they are breaking changes only if you happen to have custom
framework plugins):
1) 'mouseover', 'mousemove', 'keypress' events are no longer listened to
   'mouseover' and 'mousemove' are not used and would trigger too much
   events.
   'keypress' is also not used, and is deprecated
2) Event handlers now takes a single parameter that is an Event object
   It just makes the code a lot less complicated.
3) Event handlers do not pollute the global scope anymore

[1] https://learn.jquery.com/events/event-delegation/

Test plan:
- Go to every page that has a MARC editor and verify that plugins still
  work. This includes addbiblio.pl, additem.pl, authorities.pl,
  neworderempty.pl, orderreceive.pl
- Test plugins that use 'focus' event (for instance barcode.pl), 'blur'
  event (callnumber.pl) and 'click' event (almost all the others)
- Test that plugins work on cloned fields/subfields

-- 
You are receiving this mail because:
You are watching all bug changes.


More information about the Koha-bugs mailing list