tagsinput & typeahead: Cannot read property 'apply' of undefined

前端 未结 1 1941
抹茶落季
抹茶落季 2021-01-14 05:17

I keep getting this error when trying to use tagsinput & typeahead.

html:

相关标签:
1条回答
  • 2021-01-14 06:00

    I guess, but am not sure, that there has been made a bootstrap-tagsinput update which somehow broke the way it treats the "old" bootstrap typeahead. I have found two bugs, but not tracked completely down why.

    1'st issue
    The error "Cannot read property 'apply' of undefined" is raised in typeahead and is caused by the typeahead trying to target a undefined value. The issue is here as well. I have made a pull request for this (click for details). Hopefully my suggestion will be merged, if not you can download this forked repo. The pull request is now merged into master.

    2nd issue
    When the nasty exception was history, I noticed that bootstrap-tagsinput not is cleaning up after a selection is made in the typeahead. The selection is made but the whole string or portions of the string remains in the input box. This can be solved by using a afterSelect handler :

    $('#someElement').tagsinput({
      typeahead: {
        source: data,
        afterSelect: function() {
           this.$element[0].value = '';
        }
      }
    }) 
    

    With these two changes, bootstrap-tagsinput and boostrap3-typeahead works as expected. See demo -> http://jsfiddle.net/bao3vk2m/

    0 讨论(0)
提交回复
热议问题