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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T19:54:36+00:00 2026-05-26T19:54:36+00:00

I’ve come upon a very frustrating bug in my jquery autocomplete code. I’m working

  • 0

I’ve come upon a very frustrating bug in my jquery autocomplete code. I’m working on a book catalogue for a small library project. The autocomplete is used to aid the user in searching by subject tag or by title.

Here’s the code (currently being executed on $(document).ready();)

var autoData = [];
$.get('/search_bar', function(data){ 
    autoData = $.makeArray(data);
    console.log(autoData);
    });

    $("#search").autocomplete({
      source: function(req, responseFn){
        var re = $.ui.autocomplete.escapeRegex(req.term);
        var matcher = new RegExp("(?:^| )" + re, "gi");
        var a = $.grep(autoData, function(item, index){
          return matcher.test(item);
        });
        responseFn(a); 
      },
      minLength: 2
}); 

To focus in on the problem, I’ve limited the response from the server to a set of 3 titles which should all be returned by starting to type “pag….”

console.log(autoData) => ["Pages africaines 1", "Pages africaines 2", "Pages africaines 3"]

However, jQuery autocomplete only suggests “Pages africaines 1” and “Page africaines 3”, not (as I’d expect) “Page africaines 2” as well, unless you type out the entire title “Pages africaines 2” (at which point it appears as the only suggestion, as one would expect).

I’ve tested the RegExp/$.grep on the array above, and it seems to work fine:

autoData = ["Pages africaines 1", "Pages africaines 2", "Pages africaines 3"]

$.grep(autoData, function(item, index){ return RegExp("(?:^| )pages", "gi") })
=> ["Pages africaines 1", "Pages africaines 2", "Pages africaines 3"]

Any insight? The $.get() receives a json-encoded response from my rails backend, e.g.:

def search_bar
    output = Book.search('pages').map{|bt| bt.title }
    render :json => output.to_json
end

(where i’ve limited the autocomplete to the above example to debug). However, in the Chrome javascript console, autoData is definitely an array object as expected.

Thanks in advance!

(Note: The reason i’m using the above RegExp with “(?:^| )” instead of a word-boundary match like “\b” is because there are often unicode/accented characters in the titles, which seems to break with a “\b” match.)

  • 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-26T19:54:36+00:00Added an answer on May 26, 2026 at 7:54 pm

    Replace:

    var matcher = new RegExp("(?:^| )" + re, "gi");
    var a = $.grep(autoData, function(item, index){
      return matcher.test(item);
    });
    

    With:

    var a = $.grep(autoData, function(item, index){
      var matcher = new RegExp("(?:^| )" + re, "gi");
      return matcher.test(item);
    });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a jquery bug and I've been looking for hours now, I can't
I am reading a book about Javascript and jQuery and using one of the
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I used javascript for loading a picture on my website depending on which small
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I ran into a problem. Wrote the following code snippet: teksti = teksti.Trim() teksti
I'm working with an upstream system that sometimes sends me text destined for HTML/XML
I am trying to understand how to use SyndicationItem to display feed which is

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.