How to resolve conflict in the global event handlers set up by jQuery each time the script is executed.

How to resolve conflict in the global event handlers set up by jQuery each time the script is executed.

book

Article ID: KB0070418

calendar_today

Updated On:

Products Versions
Spotfire Analyst All

Description

When working with a DXP that includes JQuery UI customizations, specifically using functions like datepicker, the following issue may occur. The JavaScript functions work as expected when the Analyst is first started and the dxp is opened. However, upon closing and reopening the DXP (File >>Close), the JavaScript stops functioning. 

Upon reloading the browser from Tools->Developer Tools, the JQueryUI implementation works again.

Issue/Introduction

This article talks about a scenario where opening a DXP with JQuery UI customizations (e.g., datepicker) works as expected. However, after closing and reopening the DXP (without closing Analyst), the JavaScript stops working.

Environment

All

Resolution

This issue stems from the repeated overwriting of the window.CustomJquery global variable during page changes, document openings, or closures, leading to event handler disruptions in the date picker. The problem arises due to conflicting global event handlers established by jQuery UI upon each script execution.
 
To address this, consider incorporating the following code snippet into the jQueryUI script responsible for including your own(custom) instances of jQuery and jQueryUI in the Text Area.

 

var noConflict = window.jQuery.noConflict(true);
if (!window.CustomJQuery) {
    // Ensure global scope is populated with custom jQuery only once.
    window.CustomJQuery = noConflict;
}
 

This solution aims to prevent conflicts by setting up the custom jQuery in the global scope only once.


 

Additional Information

Community:  Best Practices for Writing Custom JavaScript Code in Spotfire Text Areas: Community: How to Handle Text Area Customizations Using jQuery and jQueryUI when Upgrading from Spotfire® 11.4 LTS or Earlier: Community: How to Include Your Own Instances of jQuery and jQueryUI in Text Areas: