mirror of
https://github.com/Part-DB/Part-DB-server.git
synced 2025-06-24 10:49:00 +02:00
Added a stimulus controller for tagsinput.
This commit is contained in:
parent
f276c436ae
commit
f21c339046
3 changed files with 33 additions and 42 deletions
32
assets/controllers/elements/tagsinput_controller.js
Normal file
32
assets/controllers/elements/tagsinput_controller.js
Normal 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();
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue