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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T19:23:08+00:00 2026-06-06T19:23:08+00:00

I need to add some functionality to the jQuery UI autosearch function. The problem

  • 0

I need to add some functionality to the jQuery UI autosearch function. The problem I want to solve is to allow a user to enter text in any order that will search through a list of terms and display suggestions. For example, suppose I have the following terms:

the brown cow jumped over the moon
the blue cow watched in horror
the red cow simply laughed 
the green cow got sick at such a sight
the yellow cow lost 5 bucks to the black cow
the black cow smiled at his fortune

If the user types in "the cow", I would expect the autocomplete feature to list all the results.
If I type in "brown moon", I would expect the first result to appear.
If I type in "fortune smiled", the last result would appear.

Basically this behavior allows the user to type in any string in any order and get search results.

Here’s what I’m thinking. I need to add a callback function in either the “open” or “search” events and manipulate the results there. Here’s my code so far:

$(function ()
{
    var data =
    [
        "the brown cow jumped over the moon",
        "the blue cow watched in horror",
        "the red cow simply laughed ",
        "the green cow got sick at such a sight",
        "the yellow cow lost 5 bucks to the black cow",
        "the black cow smiled at his fortune"
    ];

    $(".text-search").autocomplete(
    {
        autoFocus: true,
        source: data,
        delay: 0,
        minLength: 2,
        open: function (e, ui)
        {
            debugger;
            // what should i do here?
        },
        search: function (e, ui)
        {
            debugger;
            // what should i do here?
        }
    });
});

<div class="ui-widget">
    <label for="autocomplete">Autocomplete: </label>
    <input class="text-search">
</div>
  • 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-06-06T19:23:10+00:00Added an answer on June 6, 2026 at 7:23 pm

    I would create your own regular expression based on the text the user entered. You can then use this regular expression to test each item in the candidate list:

    $(".text-search").autocomplete({
        autoFocus: true,
        source: function(request, response) {
            var regexStr = "\\b(" + $.map($.trim(request.term).split(" "), function(term) {
                return $.ui.autocomplete.escapeRegex($.trim(term))
            }).join("|") + ")\\b",
            matcher = new RegExp(regexStr);
    
            response($.grep(data, function(value) {
                return matcher.test(value.label || value.value || value);
            }));
        },
        delay: 0,
        minLength: 2
    });
    

    The regular expression piece looks cryptic, but it’s just generating an expression using alternation (|). For example, if you type brown cow, \b(brown|cow)\b is generated which will match any string with “brown” or “cow”.

    Example: http://jsfiddle.net/hTfj9/

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

Sidebar

Related Questions

I'm using jQuery Validate for a form. I need to add some functionality so
i need to add some functionality to an asp.net application that allows the positioning
i need to add some text DIV's on each slide of a Nivoslider. I
I want to add <em> tag after textbox, if user inserted non-numeric format. $('.numeric').keypress(function
I'm enhancing an open source control to add some functionality that I need, and
I need to add some function that returns a value to a dom element.
I'm adding some functionality to an existing function. I need to insert an additional
I need to add some functionality (flush some caches and such) when a Block
Say I want to wrap a function in another function, so to add some
I want to add some functionality track certain calls to ActiveX object methods 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.