How to prevent duplicate with Bootstrap Tokenfield When using Jquery Ui Autocomplete

前端 未结 4 2032
抹茶落季
抹茶落季 2021-02-06 05:06

I am trying to implement Bootstrap Tokenfield with Jquery Ui autocomplete and so far i was able to do that except the fact that i am not able to prevent duplicates in the input

4条回答
  •  野趣味
    野趣味 (楼主)
    2021-02-06 05:52

    I think you've done it all, all you are left to do is to replace the class

    So after the first code, instead of the second code write

    $('.tokenfield').on('tokenfield:createtoken', function (event) {
        var existingTokens = $(this).tokenfield('getTokens');
        $.each(existingTokens, function(index, token) {
            if (token.value === event.attrs.value)
                event.preventDefault();
        });
    });
    

    The difference here is your class that has to be applied and it works both for Twitter Typeahead and Jquery Ui

提交回复
热议问题