Skip to main content

Search and Top Navigation

#8942 closed bug (notabug)

Opened January 02, 2013 09:01PM UTC

Closed January 02, 2013 09:19PM UTC

Last modified January 09, 2013 01:05PM UTC

This scope ignored, during array push

Reported by: ultrdev Owned by:
Priority: minor Milestone: 1.10.0
Component: ui.widget Version: 1.9.2
Keywords: Cc:
Blocked by: Blocking:
Description

I recently updated to the latest jquery ui code base 1.9.2 and jquery 1.8.3, and noticed that the 'this' scope is ignored during a js array push. The code previously worked in ui - 1.8.14 and jquery 1.7.1.

Please see http://jsfiddle.net/ZVDZZ/2/ for an example.

There are two test in there and you have to manually move the js comment tags.

The test 1 example js creates two different types of widgets: filterlist and filter. The filterlist widget creates 3 filter widgets during initialization. Initially, each filter widget has an options.selected value of a blank array array(). Then I call appendSelected in the first filter widget only, but it ignores the 'this' scope and modifies all of the filter options.selected value. You end up with all 3 of the filters have an options.selected value of array('test val'), which is incorrect. Only the first widget should have the updated value.

In test 2, I set the options.selected value to array('set val') and then call js push, and it correctly modifies the first filter options.selected to array('set val','test val'). Filters 2 and 3 correctly remain blank.

The issue occurs in all browsers (FF, Chrome and IE).

Attachments (0)
Change History (4)

Changed January 02, 2013 09:19PM UTC by scottgonzalez comment:1

_comment0: This is by design. You can't define an array as a default value. Arrays as options are now passed by reference, so that you can keep a local data store outside of the widget and have live updates. \ \ See http://jsfiddle.net/ZVDZZ/3/ for a working version of your code (not the instantiation of the filter widgets.1357161633553064
resolution: → notabug
status: newclosed

This is by design. You can't define an array as a default value. Arrays as options are now passed by reference, so that you can keep a local data store outside of the widget and have live updates.

See http://jsfiddle.net/ZVDZZ/3/ for a working version of your code (note the instantiation of the filter widgets).

Changed January 08, 2013 06:40PM UTC by TheSharpieOne comment:2

When was this added? I just noticed it. I couldn't find it documented anywhere, but it seems like it is pretty important to know.

Also: not just options have to be passed, all arrays do. I store "internal" values (_value:) which have an empty array by default, these are now outside of the scope. (see console log: http://jsfiddle.net/5Edtg/ ) Was this intentional too?

Changed January 08, 2013 07:14PM UTC by scottgonzalez comment:3

http://bugs.jqueryui.com/ticket/7718

You've never been able to define an array as a property on the prototype and have it be per-instance. That's just how JavaScript works. The only thing that changed is specific to options, where we switched from a deep copy to a shallow copy for arrays.

Changed January 09, 2013 01:05PM UTC by TheSharpieOne comment:4

I guess I never realized that. It makes sense, Thanks!