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 762045
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T15:54:38+00:00 2026-05-14T15:54:38+00:00

I am using jqueryui autocomplete widget for autocompleting a ‘country’ field but I am

  • 0

I am using jqueryui autocomplete widget for autocompleting a ‘country’ field but I am facing an issue. Suppose the user enters “in”, I want the jqueryui to list countries like ‘india’, ‘indonesia’ which start with ‘in’, but it also lists the countries which have ‘in’ somewhere in the name (like: argentina). How can I solve this issue?

jQuery(".autocomplete").autocomplete({
    source: CountrySuggestions, //CountrySuggestions is an array in javascript containing the list of countries
    minLength: 2
});

Akshey

  • 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-14T15:54:38+00:00Added an answer on May 14, 2026 at 3:54 pm

    Unfortunately, it appears as though the jQueryUI Autocomplete was made to not allow this on an array source. You can, however, hook the plugin’s _initSource function to force a “starts with” regular expression token ( ^ ) on the search as below.

    I think this was probably overlooked because the majority of its usage was thought to be in the remote retrieval. Either way, not a pretty fix, but due to the regex stripping function, it’s the only solution that came to mind.

    $.ui.autocomplete.prototype._initSource = function() {
      var array,
        url;
      if ( $.isArray(this.options.source) ) {
        array = this.options.source;
        this.source = function( request, response ) {
          // escape regex characters
          var matcher = new RegExp( "^"+$.ui.autocomplete.escapeRegex(request.term), "i" );
          response( $.grep( array, function(value) {
            return matcher.test( value.label || value.value || value );
          }) );
        };
      } else if ( typeof this.options.source === "string" ) {
        url = this.options.source;
        this.source = function( request, response ) {
          $.getJSON( url, request, response );
        };
      } else {
        this.source = this.options.source;
      }
    };
    
    $("#countries").autocomplete({
      source: ["India","Indonesia","Argentina"],
      minLength: 2
    });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm using JQuery JQueryUI's AutoComplete code. It goes to my url i provide (to
I am trying to use the jQueryUI autocomplete plugin but I am unable to
I'm using the nifty 'combobox' variant of jQuery UI Autocomplete - see here: http://jqueryui.com/demos/autocomplete/#combobox
I'm using jQuery UI, specifically Datepicker and Autocomplete, as follows: <script src=http://ajax.googleapis.com/ajax/libs/jqueryui/1.8/jquery-ui.min.js></script> <link href=http://ajax.googleapis.com/ajax/libs/jqueryui/1.8/themes/base/jquery-ui.css
I'm using the Jquery UI autocomplete on an existing project. Well, the performance is
I'm using jQuery UI's draggable and droppable libraries in a simple ASP.NET proof of
I've been using jQuery UI v1.6rc2 for a while, and wanted to upgrade to
I'm developing a site using jQuery, and jQuery UI tabs. For some reason, my
I have created an interface using jQuery UI Tabs, however one of my requirements
How can I change CSS from javascript . I'm using jQuery-ui Dialog and I

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.