Skip to content

Commit 6cdebe8

Browse files
dekajpscottgonzalez
authored andcommitted
Widget: option-method should work as getter only when argument length is 1. Fixes #9601 - Widget: calling _setOption with undefined as 3rd argument makes it a getter
(cherry picked from commit ecde7cd)
1 parent 8eefd20 commit 6cdebe8

File tree

2 files changed

+16
-5
lines changed

2 files changed

+16
-5
lines changed

tests/unit/widget/widget_core.js

+14-3
Original file line numberDiff line numberDiff line change
@@ -535,7 +535,7 @@ test( ".option() - delegate to ._setOptions()", function() {
535535
});
536536

537537
test( ".option() - delegate to ._setOption()", function() {
538-
expect( 2 );
538+
expect( 3 );
539539
var div,
540540
calls = [];
541541
$.widget( "ui.testWidget", {
@@ -554,6 +554,11 @@ test( ".option() - delegate to ._setOption()", function() {
554554
deepEqual( calls, [{ key: "foo", val: "bar" }],
555555
"_setOption called for single option" );
556556

557+
calls = [];
558+
div.testWidget( "option", "foo", undefined );
559+
deepEqual( calls, [{ key: "foo", val: undefined }],
560+
"_setOption called for single option where value is undefined" );
561+
557562
calls = [];
558563
div.testWidget( "option", {
559564
bar: "qux",
@@ -566,9 +571,9 @@ test( ".option() - delegate to ._setOption()", function() {
566571
});
567572

568573
test( ".option() - deep option setter", function() {
569-
expect( 6 );
574+
expect( 9 );
570575
$.widget( "ui.testWidget", {} );
571-
var div = $( "<div>" ).testWidget();
576+
var result, div = $( "<div>" ).testWidget();
572577
function deepOption( from, to, msg ) {
573578
div.data( "ui-testWidget" ).options.foo = from;
574579
$.ui.testWidget.prototype._setOption = function( key, value ) {
@@ -580,6 +585,12 @@ test( ".option() - deep option setter", function() {
580585
deepOption( { bar: "baz" }, { bar: "qux" }, "one deep" );
581586
div.testWidget( "option", "foo.bar", "qux" );
582587

588+
deepOption( { bar: "baz" }, { bar: undefined }, "one deep - value = undefined" );
589+
590+
result = div.testWidget( "option", "foo.bar", undefined );
591+
592+
deepEqual ( result, div, "option should return widget on successful set operation" );
593+
583594
deepOption( null, { bar: "baz" }, "null" );
584595
div.testWidget( "option", "foo.bar", "baz" );
585596

ui/jquery.ui.widget.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -315,12 +315,12 @@ $.Widget.prototype = {
315315
curOption = curOption[ parts[ i ] ];
316316
}
317317
key = parts.pop();
318-
if ( value === undefined ) {
318+
if ( arguments.length === 1 ) {
319319
return curOption[ key ] === undefined ? null : curOption[ key ];
320320
}
321321
curOption[ key ] = value;
322322
} else {
323-
if ( value === undefined ) {
323+
if ( arguments.length === 1 ) {
324324
return this.options[ key ] === undefined ? null : this.options[ key ];
325325
}
326326
options[ key ] = value;

0 commit comments

Comments
 (0)