Solved

Jquery ui autocomplete: Having trouble with clicking element in autosuggest list and populating input field.

Posted on 2014-10-11
2
324 Views
Last Modified: 2014-11-01
Hello, I'm having trouble with clicking a list element in autosuggest list and populating input field. It was working without the introduction to the top part (Highlighting) but i'm just not seeing what the issue is with that addition. Everything else is working perfectly.

(function( $ ) {
    // Custom autocomplete instance.
    $.widget( "app.autocomplete", $.ui.autocomplete, {

        // Which class get's applied to matched text in the menu items.
        options: {
            highlightClass: "ui-state-highlight"
        },

        _renderItem: function( ul, item ) {

            // Replace the matched text with a custom span. This
            // span uses the class found in the "highlightClass" option.
            var re = new RegExp( "(" + this.term + ")", "gi" ),
                cls = this.options.highlightClass,
                template = "<span class='" + cls + "'>$1</span>",
                label = item.label.replace( re, template ),
                $li = $( "<li/>" ).appendTo( ul );

            // Create and return the custom menu item content.
            $( "<a/>" ).attr( "href", "#" )
                       .html( label )
                       .appendTo( $li );

            return $li;

        }

    });

    // Create autocomplete instances.
    $(function() {

        $('.input-search').autocomplete({
            source: function(query, response) {
                $.ajax({
                    url: "app/func/func_search.cfc?method=search&returnformat=json",
                    dataType: "json",
                    data: {
                        searchPhrase: query.term
                    },
                    success: function(result) {
                    response(result);
                    },
                    select: function( event, ui ) {
                    log( ui.item ?
                    "Selected: " + ui.item.value + " aka " + ui.item.id :
                    "Nothing selected, input was " + this.value );
                    }
                });
            }
        });

      });

})( jQuery );

Open in new window

0
Comment
Question by:brihol44
2 Comments
 
LVL 82

Accepted Solution

by:
leakim971 earned 500 total points
ID: 40376067
check line 17 : item.label.replace( re, template ),

replace label by value

so you've :
item.value.replace( re, template ),
0
 

Author Closing Comment

by:brihol44
ID: 40417757
Oh right! Thx
0

Featured Post

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

Requirements JQuery 1.6+ HTML CSS Introduction This article was inspired by an EE question (http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/Q_28372511.html) on how to make a page show some balloons animate up a page…
I found this questions asking how to do this in many different forums, so I will describe here how to implement a solution using PHP and AJAX. The logical flow for the problem should be: Write an event handler for the first drop down box to get …
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)

707 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now