Twitter typeahead different meaning to display

    //javascript
    var customer = new Bloodhound({
    datumTokenizer: Bloodhound.tokenizers.obj.whitespace('name'),
    queryTokenizer: Bloodhound.tokenizers.whitespace,

    prefetch: 'include/customer.json'
    });

    $('.typeahead').typeahead(null, {
    name: 'customer',
    display: 'name',
    source: customer
    });


    //json
    [
    {"identity":"1","name":"Uzumaki Naruto"},
    {"identity":"2","name":"Monkey D. Luffy"},
    {"identity":"3","name":"Ichigo Kurosaki"}
    ]

   //html
   <input class="typeahead" type="text" name="customer"/>

      

is it possible in the typeahead plugin to search and display ' name

' and when I submit the form it will give me the value ' identity

'. Btw i`m uses 0.11.1v of type head. TIA

+3


source to share


1 answer


To accomplish what you want, you have to use two input fields.

// html
<input type="text" name="customer_typeahead" class="typeahead"/>
<input type="hidden" name="customer" id="customer_identity" />

// typeahead code
$('.typeahead').typeahead(null, {
  ....
}).bind('typeahead:select', function(ev, suggestion) {
  $('#company_identity').val(suggestion.identity);
});

      



This makes it so that when you select a sentence, it will set the input value customer

.

+1


source







All Articles