[Koha-bugs] [Bug 18183] New: jQuery append error related to script tags in cloneItemBlock

bugzilla-daemon at bugs.koha-community.org bugzilla-daemon at bugs.koha-community.org
Tue Feb 28 15:50:51 CET 2017


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

            Bug ID: 18183
           Summary: jQuery append error related to script tags in
                    cloneItemBlock
 Change sponsored?: ---
           Product: Koha
           Version: master
          Hardware: All
                OS: All
            Status: NEW
          Severity: enhancement
          Priority: P5 - low
         Component: Acquisitions
          Assignee: koha-bugs at lists.koha-community.org
          Reporter: m.de.rooy at rijksmuseum.nl
        QA Contact: testopia at bugs.koha-community.org

This is a strange javascript error that I experienced on a 3.22 system and
could not reproduce with the current (modified) framework in master. But since
the code is essentially the same, it might still be possible.

The js error is:
TypeError: document.getElementById(...) is null
The line in koha-tmpl/intranet-tmpl/prog/js/additem.js that causes this error
is:
$(clone).append(data);
While running append, jQuery seems to call .domManip and .globalEval
internally.
The result on the interface is that you do not have an item block when
receiving an order (AcqCreateItem=receiving).

Note that data comes from services/itemrecorddisplay.pl and is a very long
string containing all item fields and even script tags for plugins. Between the
ACQ framework in 3.22 and in master (copied from Default), I noticed some
smaller changes in the lines for plugins.
Since the js variable "clone" contains a jQuery object for an element that is
not yet added to the page, I could imagine a getElementById error. But it does
not always occur, so some other condition must be triggered too. This condition
appears to be connected to the script tags, since removing all plugins from the
ACQ framework in 3.22 made the error disappear (no solution however).

Some interesting comments on jQuery's handling of appending script tags are
found in http://stackoverflow.com/questions/610995/cant-append-script-element

Triggered by the getElementById error, I rearranged a few lines in
cloneItemBlock so that I appended clone (the 'floating' div field for the new
item) first to the outeritemblock div on the page and after that I appended the
data string (item fields and script tags) to clone.
This resolved the js error on 3.22 and did not affect master.

Conclusion: We seem to stumble over a problem with our plugin script tags in
jQuery's script evaluation when clone is not bound to the page yet.
The proposed patch just adds this workaround touching three lines. If we would
like to change (again) the way we handle script tags for plugins, we will need
much more effort.

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


More information about the Koha-bugs mailing list