Ticket #7489 (closed bug: notabug)

Opened 4 years ago

Last modified 4 years ago

autocomplete fails when new widget 'jqn.menu' is created

Reported by: kccarter Owned by:
Priority: minor Milestone: 1.9.0
Component: ui.autocomplete Version: 1.8.1
Keywords: Cc:
Blocking: Blocked by:

Description (last modified by rdworth) (diff)

the issue is when a menu widget is created in a different namespace ie: 'jqn.menu' the menu property of the autocomplete control no longer has access to the methods defined in 'ui.menu' the menu object is now referencing 'jqn.menu'.

this issue was observed in version 1.8.1. based on the look I have taken at version 1.8.13, I believe the issue is still present there as well.

Change History

comment:1 Changed 4 years ago by rdworth

  • Status changed from new to closed
  • Resolution set to invalid
  • Description modified (diff)

This is as designed. The autocomplete widget depends on ui.menu via $.fn.menu. That way you can provide your own $.fn.menu and it will depend on it instead of the one that lives at $.ui.menu. If you want your own menu that doesn't fill that role, give it a different alias in the $.fn. namespace with $.widget.bridge and then use bridge to restore the $.fn.menu -> $.ui.menu alias:

$.widget.bridge( "jqnMenu", $.jqn.menu );
$.widget.bridge( "menu", $.ui.menu );

This assumes you load autocomplete (which includes ui.menu) first, then jqn.menu. If you load jqn.menu before autocomplete then only the first line above should be needed. If you have additional questions about this, please ask on the forum  http://forum.jquery.com/using-jquery-ui

For more on the widget bridge, see  http://www.erichynds.com/jquery/using-jquery-ui-widget-factory-bridge/

comment:2 Changed 4 years ago by rdworth

Even though I believe this is as-designed today, it's something I think we should consider fixing in a future major release. I've added a comment to that effect on the Widget factory wiki page:  http://wiki.jqueryui.com/Widget-factory#commentnum1308445289 . Feel free to follow up there.

comment:3 Changed 4 years ago by kccarter

I was thinking about this problem and I think I came up with a reasonable solution. this could would reside in the jquery.ui.widget.js file right after the var _remove line.

$.fn.extend({

widget: function (name, options) {

var parts = String(name).split('.'), namespace = parts[0], name = parts[1], _widget = $[namespace][name];

/* when calling into a namespace in order to set the /*this*/ variable we have to instanciate a new instance of the widget. could we pass a reference to the widgets prototype? if we did does it risk corruption of that widget's class?*/

if ($.isFunction(_widget)) {

_widget.call(new _widget(), options, this); /*_widget.call(_widget.prototype, options, this);*/

}

return this;

}

});

Note: See TracTickets for help on using tickets.