1

I am using Jquery autocomplete and array as source and I want to display the label instead of the value because i am storing the value in a different variable where it is not displayed in the form. But this is what they say in the documentation:

The label property is displayed in the suggestion menu. The value will be inserted into the input element when a user selects an item.

Sample images

Searching:
While searching
Selecting:
After selecting

Codes:
Array:

var searchcustomer_arr = [{label:"ASD CUSTOMER",value:1},
                          {label:"Customer 2",value:2}]

Javascript:

$("#customer" ).autocomplete({
  source: searchcustomer_arr,
  minlength: 2
});

1 Answer 1

4

Try this is working :-

$("#customer").autocomplete({
  source:[
          {label:"ASD CUSTOMER",value:1},
          {label:"Customer 2",value:2}
         ],
  minLength: 2,
  select: function(event, ui) {
      event.preventDefault();
      $("#customer").val(ui.item.label);
  }
});

Working Demo

Sign up to request clarification or add additional context in comments.

Comments

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.