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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T18:51:54+00:00 2026-05-27T18:51:54+00:00

I want to do a very specific stuff with jQuery and autocomplete, and I

  • 0

I want to do a very specific stuff with jQuery and autocomplete, and I didn’t find an adequate answer on the web. My first problem is that all the methods I could find on the Web don’t work (parse, formatItem and so on).

What is strange is that the autocomplete works perfectly with the following code, but ignores all the other “customize” methods (parse, formatItem and so on).

/* autocompletion */
$( '#metier' ).autocomplete({
  source: '/json/metiers/categories/mix/',
  minLength: 2,
  select: function(event, ui) {
    /* item look like '(XXXX) yyyy'
       => remove '(XXXX)' then forbid 
          autocomplete() to assign its own value
          via 'return false' :
    */
    var v=ui.item.value;
    $('#metier').val(v.substr(v.indexOf(') ')+1));
    return false;
  }
});

Here’s what I put in my <header>: I’m using the latest versions of everything so I don’t know what’s wrong with it:

<script src="https://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js" type="text/javascript"></script>
<script src="https://ajax.googleapis.com/ajax/libs/jqueryui/1/jquery-ui.min.js" type="text/javascript"></script>
<link rel="stylesheet" href="http://ajax.googleapis.com/ajax/libs/jqueryui/1/themes/base/jquery-ui.css" type="text/css" media="screen" />

Here’s what I’ve done and it works:

  • add autocomplete to an input field
  • when the selection is made, remove the (XXX) at the beginning of the selection and fill the input field with what’s left

Here’s what I’m trying to do:

  • add autocomplete to an input field
  • when the AJAX returns, stock the resulting array (which is JSON) in a global variable (to be able to retrieve a corresponding field (url actually) later on
  • for each label that will be shown in the list, create a custom display (there’s always a (XXX) at the beginning, i’d like it to be colored), and create a custom id (depending on the AJAX return).
  • when the selection is made, remove the (XXX) at the beginning of the selection and fill the input field with what’s left, extract the id number from the id of the selection, and stock the corresponding field url found in the global array in a global variable for later use.

I’m using the jQuery autocomplete component, and the AJAX call returns something like:

[
    {
        "id":"229",
        "value":"(Category) General category of that stuff",
        "url":"//"
    },
    {
        "id":"240",
        "value":"(Category) General category of that stuff",
        "url":"/toto/detail/tata"
    },
    {
        "id":"3655",
        "value":"(Detail) Very detailed stuff",
        "url":"/toto/detail/tata"
    }
]

I’ve already looked at:

  • stackoverflow what-does-formatresult-and-formatitem-options-do-in-jquery-autocomplete
  • blog.schuager.com jquery-autocomplete-json-apsnet-mvc
  • stackoverflow json-with-autocomplete
  • jqueryui autocomplete custom-data / jqueryui autocomplete custom-data

But nothing could help me…

  • 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-27T18:51:54+00:00Added an answer on May 27, 2026 at 6:51 pm

    There is a tutorial on how to do custom display on the jQuery UI site:

    • http://jqueryui.com/demos/autocomplete/#custom-data

    To do custom display of the items in the drop-down, it chains a .data("autocomplete") call after the .autocomplete call, and adds a _renderItem function to the data that is retrieved.

    Here’s some code to do the auto-coloring of the items in parens:

    http://jsfiddle.net/VnUv8/

    .data("autocomplete")._renderItem = function(ul, item) {
        var v = item.value;
        return $("<li></li>")
            .data("item.autocomplete", item)
            .append(
                "<a>"
                    + "<span class='hilightItem'>"
                        + v.substr(0, v.indexOf(') ') + 1)
                    + "</span>"
                    + " " + v.substr(v.indexOf(') ') + 2)
                + "</a>"
            )
            .appendTo(ul);
    };
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to create an application that will automate a very specific build process
So, lets say I'm writing a web server and I want to support very
I'm having a problem trying to return a specific record using jQuery and JSON.
This is a very general question that's not related to a specific language. I'm
In my previous question , I wasn't very specific over my problem (scraping with
It seems that if I want to create a very basic Cocoa application with
For a very specific reason I want to select ListViewItem s on mouse button
In an app I have very reused Activity, that shows a list of stuff
I just want a very handy way to extract the numbers out of a
I want to some very basic IronRuby tests, such as checking the syntax on

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.