typeahead.js - Pass value from DOM element into typeahead with bloodhound -


i pass value hidden input field search remote url parameter in bloodhound.

the variable dynamic , updated every time modal popup gets open. initial value null , believe that's why not working @ all:

url: url + 'equipment/getsuggestions/' + $('#equipment-type-input').val() + '/%query', 

as can see i'm getting jquery value empty. because getting once when plugin initialized?

here full script:

// instantiate bloodhound suggestion engine var suggestions = new bloodhound({     datumtokenizer: function (datum) {         return bloodhound.tokenizers.whitespace(datum.value);     },     querytokenizer: bloodhound.tokenizers.whitespace,     remote: {         url: url + 'equipment/getsuggestions/' + $('#equipment-type-input').val() + '/%query',         wildcard: '%query',         filter: function (movies) {             // map remote source json array javascript object array             return $.map(movies, function (movie) {                 return {                     value: movie                 };             });         }     } });  // initialize bloodhound suggestion engine suggestions.initialize();  // instantiate typeahead ui $('#equipment-id-input').typeahead(null, {     displaykey: 'value',     source: suggestions.ttadapter() }); 

you can set bloodhound's remote this:

remote: {   url: '/equipment/getsuggestions/%equipment/%query',   replace: function(url) {     return url.replace('%equipment', $('#equipment-type-input').val()).replace('%query', $('input.typeahead.tt-input').val());   },   filter: function (movies) {     // map remote source json array javascript object array     return $.map(movies, function (movie) {       return {         value: movie       };     });   } } 

you don't need wildcard anymore since have replace %query in replace parameter.


Comments

Popular posts from this blog

javascript - Using jquery append to add option values into a select element not working -

Android soft keyboard reverts to default keyboard on orientation change -

Rendering JButton to get the JCheckBox behavior in a JTable by using images does not update my table -