Search and Top Navigation
#15019 closed bug (fixed)
Opened August 02, 2016 10:28AM UTC
Closed August 04, 2016 01:05PM UTC
Last modified August 04, 2016 01:05PM UTC
Widget instance does not return undefined for empty jQuery collection
Reported by: | victor-homyakov | Owned by: | scottgonzalez |
---|---|---|---|
Priority: | minor | Milestone: | 1.12.1 |
Component: | ui.widget | Version: | 1.12.0 |
Keywords: | Cc: | ||
Blocked by: | Blocking: |
Description
Current versions of jQuery UI return following values for widget instance:
- When widget is initialized: widget instance
- When widget is not initialized:
undefined
- When jQuery collection is empty: empty jQuery collection
https://jsfiddle.net/gtmbwyb9/
This is a bit misleading because as stated in https://api.jqueryui.com/jQuery.widget/#method-instance, if the element does not have an associated instance,
undefinedis returned. I ran into that problem in single-page application, while I was simply checking for non-undefined widget instance before calling widget methods. In case when DOM element is missing, additional check is required.
In [changeset:"3dd8a09b441d65445f2b6a7c73e72af65445d5da" 3dd8a09]: