0

I have implemented jquery UI autocomplete.Mouseover is working properly on list but when I use down arrow key it display id also in text box which I don't want as given below: for example id 119 is displaying in below image.

enter image description here

What can I do now?

Thanks

1 Answer 1

1

You should have a look on the doc : http://api.jqueryui.com/autocomplete/#method-_renderItem The "_renderItem" allows you to customize the displayed list.

_renderItem: function( ul, item ) {
  return $( "<li>" )
    .attr( "data-value", item.value )
    .append( $( "<a>" ).text( item.label ) )
    .appendTo( ul );
}

Edit : here is a complete code I use to display both ID and item name in the list :

$("input.project-code").autocomplete({
        minLength: 2,
        source: availableProjects,
        focus: function( event, ui ) {
            $(this).val(ui.item.value);
            return false;
        },
        select: function( event, ui ) {
            $(this).val(ui.item.value);
            $(this).change();
            return false;
        }
    })
    .data( "ui-autocomplete" )._renderItem = function( ul, item ) {
        return $( "<li>" )
            .append( "<a>" + item.value + " - " + item.name + "</a>" )
            .appendTo( ul );
    };
Sign up to request clarification or add additional context in comments.

3 Comments

Actually in my case when I use down arrow key id value is displaying but I don't want that So what I have to do for that?
I think you can have a look on this part of the code : focus: function( event, ui ) { $(this).val(ui.item.value); return false; },
The focus: part allows you to choose what to put in the input when you focus an item with your arrow keys

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.