RVRNEXT-30 initialize TomSelect in community_members.js
All checks were successful
rvr-nextgen/pipeline/pr-master This commit looks good

This commit is contained in:
Bence Pőcze 2023-05-02 02:22:57 +02:00
parent c00be9a49d
commit 5053d37388
Signed by: bence
GPG Key ID: DC5BD6E95A333E6D

View File

@ -1,17 +1,31 @@
(function () {
const element = document.getElementById('newMember').elements['user_id'];
const choices = new Choices(element, {
noResultsText: 'No users found',
noChoicesText: 'Start typing to search users'
const select = new TomSelect(element, {
placeholder: 'User',
valueField: 'value',
labelField: 'label',
searchField: 'label',
loadThrottle: 300,
load: function (query, callback) {
var self = this;
RVR.httpRequest('GET', searchUserUrl.replace('QUERY', encodeURIComponent(query)), function () {
self.clearOptions();
callback(this.response.results);
});
},
});
element.addEventListener('search', RVR.debounce(async function (e) {
RVR.httpRequest('GET', searchUserUrl.replace('QUERY', encodeURIComponent(e.detail.value)), function () {
choices.setChoices(this.response.results, 'value', 'label', true);
});
}));
select.on('change', function (value) {
this.clearOptions();
});
element.addEventListener('choice', function () {
choices.setChoices([], 'value', 'label', true);
select.on('blur', function (value) {
this.clearOptions();
});
select.on('type', function (value) {
if (value === '') {
this.clearOptions();
}
});
})();