Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to extend jQuery UI widget _create method?

Tags:

jquery-ui

I'm having a LOT of pain trying to do something very simple : extend a jQuery UI widget, namely the autocomplete one.

Here is what I am doing :

(function($) {
    $.widget("my.autocomplete", $.extend({}, $.ui.autocomplete.prototype, {     
        _create: function() {
            $.Widget.prototype._create.apply(this, arguments);
        },
    }));
})(jQuery);

Of course, it doesn't work even though it is exactly what the official jQuery UI documentation recommends :

http://jqueryui.com/docs/Developer_Guide

Can someone help on this ? I'm confused and have been stuck for many hours now...

Thanks by advance,

Eric.

like image 719
Eric MORAND Avatar asked Feb 07 '11 14:02

Eric MORAND


People also ask

How is the default formatting for a jQuery UI widget done?

The basic formatting of the accordion is done by the CSS for jQuery UI, but you can use CSS to format the contents within the panels.

What is jQuery UI widget?

a jQuery UI widget is a specialized jQuery plug-in. Using plug-in, we can apply behaviours to the elements. However, plug-ins lack some built-in capabilities, such as a way to associate data with its elements, expose methods, merge options with defaults, and control the plug-in's lifetime.

What is a factory widget?

The widget factory defines how to create and destroy widgets, get and set options, invoke methods, and listen to events triggered by the widget. By using the widget factory to build your stateful plugins, you are automatically conforming to a defined standard, making it easier for new users to start using your plugins.


1 Answers

OK, I've found the answer after many hours of confusion :

$.ui.autocomplete.prototype._create.apply(this, arguments);

Instead of :

$.Widget.prototype._create.apply(this, arguments);

Working like a charm...

like image 54
Eric MORAND Avatar answered Sep 27 '22 15:09

Eric MORAND