Added a stimulus controller for tagsinput.

This commit is contained in:
Jan Böhmer 2022-03-06 23:45:45 +01:00
parent f276c436ae
commit f21c339046
3 changed files with 33 additions and 42 deletions

View file

@ -0,0 +1,32 @@
import {Controller} from "@hotwired/stimulus";
import Bloodhound from "corejs-typeahead/dist/bloodhound";
import 'corejs-typeahead';
import '../../js/lib/tagsinput';
import '../../css/tagsinput.css'
export default class extends Controller {
connect() {
if(this.element.dataset.autocomplete) {
const engine = new Bloodhound({
//@ts-ignore
datumTokenizer: Bloodhound.tokenizers.obj.whitespace(''),
//@ts-ignore
queryTokenizer: Bloodhound.tokenizers.obj.whitespace(''),
remote: {
url: this.element.dataset.autocomplete,
wildcard: 'QUERY'
}
});
$(this.element).tagsinput({
typeaheadjs: {
name: 'tags',
source: engine.ttAdapter()
}
});
} else { // Init tagsinput without typeahead
$(this.element).tagsinput();
}
}
}