how can i set a default value in typeahead . i tried many solutions here, but no one seems to work .
Like tagApi.tagsManager("pushTag", 'deafulttag');
Below is my whole code .
$(document).ready(function() {
var tagApi = $(".tm-input").tagsManager();
jQuery(".typeahead").typeahead({
name: 'job_skill',
displayKey: 'category',
source: function (query, process) {
return $.get('ajaxpro.php', { query: query }, function (data) {
data = $.parseJSON(data);
return process(data);
});
},
afterSelect :function (item){
tagApi.tagsManager("pushTag", item);
}
});
});
Thanks in advance for the help .
You could pre-fill the element with a value?
jQuery(".typeahead").typeahead('val',"test");
Source: Bootstrap typeahead - How to set the default value manually
Edit:
In your example you'd want to initiate typeahead with this value something like below rather than re-initialising it:
$(document).ready(function() {
var tagApi = $(".tm-input").tagsManager();
jQuery(".typeahead").typeahead({
name: 'job_skill',
displayKey: 'category',
val: 'test',
source: function (query, process) {
return $.get('ajaxpro.php', { query: query }, function (data) {
data = $.parseJSON(data);
return process(data);
});
},
afterSelect :function (item){
tagApi.tagsManager("pushTag", item);
}
});
});