Calling Prototype methods in Javascript

Sometimes when one is working with jquery plugins, one desires to call a juicy method in the control.  And you know the method is there because you can see it in action.  But you can’t call it…  Because it’s in the prototype…

This very thing happened to me today using a plugin called Chosen.  Chosen is an extension of the drop down list which allows the user to filter the list of items.  Pretty cool idea, and it doesn’t look bad either.  The problem occurred with switching between chosen controls with the tab key.   When tab is pressed, the value of the first control is set and the “changed” event is fired.  In the change event, an ajax call is made to populate the values in the second control (based on the value of the first control).  The problem was I could never set focus to the second control once the populate was finished.  What I finally had to do was call the close and activate prototype methods like so:

$(portfolioCtrl).data('chosen').close_field();
property.data('chosen').activate_action();
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s