Skip to content

Commit ecde7cd

Browse files
dekajpjzaefferer
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
1 parent 9620812 commit ecde7cd

File tree

2 files changed

+16
-5
lines changed

2 files changed

+16
-5
lines changed

tests/unit/widget/widget_core.js

Lines changed: 14 additions & 3 deletions
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.testWidget( "instance" ).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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -321,12 +321,12 @@ $.Widget.prototype = {
321321
curOption = curOption[ parts[ i ] ];
322322
}
323323
key = parts.pop();
324-
if ( value === undefined ) {
324+
if ( arguments.length === 1 ) {
325325
return curOption[ key ] === undefined ? null : curOption[ key ];
326326
}
327327
curOption[ key ] = value;
328328
} else {
329-
if ( value === undefined ) {
329+
if ( arguments.length === 1 ) {
330330
return this.options[ key ] === undefined ? null : this.options[ key ];
331331
}
332332
options[ key ] = value;

0 commit comments

Comments
 (0)