Skip to content

Commit 512825d

Browse files
committed
Widget: Added ability to define how to find options on init. Fixes #6158 - Widget: Ability to define new methods for gathering options on init.
1 parent c3b282f commit 512825d

File tree

2 files changed

+34
-1
lines changed

2 files changed

+34
-1
lines changed

tests/unit/widget/widget_core.js

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,32 @@ test("merge multiple option arguments", function() {
156156
});
157157
});
158158

159+
test( "_getCreateOptions()", function() {
160+
expect( 1 );
161+
$.widget( "ui.testWidget", {
162+
options: {
163+
option1: "valuex",
164+
option2: "valuex",
165+
option3: "value3",
166+
},
167+
_getCreateOptions: function() {
168+
return {
169+
option1: "override1",
170+
option2: "overideX",
171+
};
172+
},
173+
_create: function() {
174+
same( this.options, {
175+
disabled: false,
176+
option1: "override1",
177+
option2: "value2",
178+
option3: "value3"
179+
});
180+
}
181+
});
182+
$( "<div>" ).testWidget({ option2: "value2" });
183+
});
184+
159185
test( "re-init", function() {
160186
var div = $( "<div></div>" ),
161187
actions = [];

ui/jquery.ui.widget.js

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ $.Widget.prototype = {
145145
this.element = $( element );
146146
this.options = $.extend( true, {},
147147
this.options,
148-
$.metadata && $.metadata.get( element )[ this.widgetName ],
148+
this._getCreateOptions(),
149149
options );
150150

151151
var self = this;
@@ -157,6 +157,13 @@ $.Widget.prototype = {
157157
this._trigger( "create" );
158158
this._init();
159159
},
160+
_getCreateOptions: function() {
161+
var options = {};
162+
if ( $.metadata ) {
163+
options = $.metadata.get( element )[ this.widgetName ];
164+
}
165+
return options;
166+
},
160167
_create: function() {},
161168
_init: function() {},
162169

0 commit comments

Comments
 (0)