Opened 7 years ago

Closed 7 years ago

Last modified 7 years ago

#15019 closed bug (fixed)

Widget instance does not return undefined for empty jQuery collection

Reported by: Victor Homyakov Owned by: Scott González
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, undefined is 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.

Change History (2)

comment:1 Changed 7 years ago by Scott González

Owner: set to Scott González
Resolution: fixed
Status: newclosed

In 3dd8a09:

Widget: instance() should return undefined for empty sets

Fixes #15019

comment:2 Changed 7 years ago by Scott González

Milestone: none1.12.1
Note: See TracTickets for help on using tickets.