0

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 .

Ele
  • 33,468
  • 7
  • 37
  • 75
phpdev
  • 89
  • 2
  • 10

1 Answers1

1

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);
        }
    });
});
mquinn
  • 454
  • 4
  • 14