I have created a jQueryUI widget called "Picklist" using the widget factory. It works great. However, because it is a widget, it doesn't respond to the val() method.
I have a function that is looping through an array to assign data to web controls. For the most part, I can just use the jQuery method val() to assign the value. But that doesn't work for my widget.
I instead have to manually check if the widget exists on the control, and then call the widget version of val() to do the assignment. This seems terribly inefficient and the antithesis of good object oriented design.
for (var i = 0; i < ControlData.length; i++)
{
var mapping = ControlData[i];
$('#' + mapping.controlName).val(mapping.value);
if ($('#' + mapping.controlName).data('Erik-Picklist'))
{
$('#' + mapping.controlName).Picklist("option", { val: mapping.value });
}
}
Is there a way to have val() map to a widget method on a certain element? I was thinking there might be a method I could call on the element that would map the val() method to the Picklist's val() method, but I haven't seen any example of that sort of thing.