Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 5951217
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T17:30:19+00:00 2026-05-22T17:30:19+00:00

I have the following script using the jQueryUI autocomplete widget. It calls some function

  • 0

I have the following script using the jQueryUI autocomplete widget. It calls some function whenever a menu item in the selection box is being selected:

<script type="text/javascript">
    $(function() {
        $( "#tags" ).autocomplete({
            source: [ "ActionScript", "AppleScript", "Asp"],
            select: function() { 
                console.log("Element has been selected");
            }
        });
    });
</script>

<div class="ui-widget">
    <label for="tags">Tags: </label>
    <input id="tags">
</div>

This works nicely. But I need this method in a multiple of instances of the autocomplete widget, so I prefer extending the autocomplete widget using the widget factory.

This works nicely whenever I want to override methods of the autocomplete plugin:

$.widget("ui.myAutocomplete", $.extend({}, $.ui.autocomplete.prototype, {
    search: function( value, event ) {
        // this WORKS!
        console.log('overriding autocomplete.search')

        return $.ui.autocomplete.prototype.search.apply(this, arguments);
    }
}));

However, I have no clue how to do that for the underlying menu widget.

I tried to override the _init method and binding a function to the select event. However this does not work as I don’t know how to access the bind method of the menu-widget (or this menu widget is not yet there at this point during runtime)

$.widget("ui.myAutocomplete", $.extend({}, $.ui.autocomplete.prototype, {
    _init: function() {
        // this does NOT work. 
        this.bind('select', function() { console.log('item has been selected') })

        return $.ui.autocomplete.prototype._init.apply(this, arguments);
    }
}));
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-22T17:30:19+00:00Added an answer on May 22, 2026 at 5:30 pm

    I think you’re close; you should be overriding _create instead of _init:

    $.widget("ui.myAutocomplete", $.extend({}, $.ui.autocomplete.prototype, {
        _create: function() {
            // call autocomplete's default create method:
            $.ui.autocomplete.prototype._create.apply(this, arguments);
    
            // this.element is the element the widget was invoked with
            this.element.bind("autocompleteselect", this._select);
        },
        _select: function(event, ui) {
            // Code to be executed upon every select.
        }
    }));
    

    Usage:

    $("input").myAutocomplete({
        /* snip */
    });
    

    Here’s a working example: http://jsfiddle.net/EWsS4/

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have Divs show and hide (with an animation) using the following script (I
Ok, I have been using the following script for over a year now to
I have the following script: Timer=0; function countdown(auctionid){ var auctions; var divs; Timer=Timer+1; if((Timer%10==0)||(Timer==1)){
i have the following script i am using to scrap data from my uni
I have the following script: <script type=text/javascript> $(document).ready(function(){ document.write(<script type=\text/javascript\ src=\http://site.com/script.js\><\/script>); }); </script> When
I'm using following script to mark current page with a.active on the URL. $(function
I have a varable var file = "testfile.txt"; I am using the following script
I have the following script which does not work. it should be using jquery
I have the following script element in my web page: <script src=default.js type=text/javascript></script> Using
I have the following script. It replaces all instances of @lookFor with @replaceWith in

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.