I want to have a jquery ui widget option be a string by default, but I want it to be able to overridden by an object. When I do this, I actually get the string converted to an object in some strange way, and then extended with whatever object I pass in.
$.widget("ui.test", {
options: {
anOption: "a,b,c"
},
_create: function() {
console.log(this.options);
}
});
$('div').test({
anOption: {
a: 'A'
}
});
If I skip passing in the option to the widget, it will be received as a string in the _create method. If I pass in an object, the strange behavior occurrs. In chromes js console log I get this, which is not what I want.
Object
anOption: Object
0: "a"
1: ","
2: "b"
3: ","
4: "c"
a: "A"
How do I solve this?
jsfiddle: http://jsfiddle.net/MatteS75/s9wK2/
If you change the option after the widget is created, it will overwrite the option with the object that you want. Is this acceptable?
This is a bug that has been fixed very recently:
http://bugs.jqueryui.com/ticket/8713
https://github.com/jquery/jquery-ui/commit/9b908878ae3a9c0fbbd9958b579f223a648c5c69