0

I am using bootstrap-tokenfield http://sliptree.github.io/bootstrap-tokenfield/ with jquery autocomplete. I want tagging with autocomplete content(from dropdown only). When user is inputting something and hit enter key it automatically creates tags. I dont want to allow this feature to the users. Is there any option/flag to set it? Any help would be appreciated. Thanks in advance.

Sonal S.
  • 1,444
  • 1
  • 15
  • 31

1 Answers1

0

Using listener tokenfield:createtoken you can validate the token before creating it.

Info: http://sliptree.github.io/bootstrap-tokenfield/#events

$('#tokenfield').on('tokenfield:createtoken', function (event) {
    var exists = false;
    $.each(yourSource, function(index, value) {
        if (event.attrs.value === value) {
            exists = true;
        }
    });
    if(!exists) {
        event.preventDefault(); //prevents creation of token
    }
});
aries23
  • 326
  • 1
  • 5
  • 11