Opened 6 months ago

Closed 6 months ago

Last modified 6 months ago

#15019 closed bug (fixed)

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, 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 6 months ago by scottgonzalez

  • Owner set to scottgonzalez
  • Resolution set to fixed
  • Status changed from new to closed

In 3dd8a09:

Widget: instance() should return undefined for empty sets

Fixes #15019

comment:2 Changed 6 months ago by scottgonzalez

  • Milestone changed from none to 1.12.1
Note: See TracTickets for help on using tickets.