Skip to content

Commit

Permalink
Mejoras para autocomplete multiple
Browse files Browse the repository at this point in the history
  • Loading branch information
hmartinez85 committed Jan 29, 2025
1 parent 8d0464d commit faf9dd2
Showing 1 changed file with 12 additions and 23 deletions.
35 changes: 12 additions & 23 deletions src/rup.select.js
Original file line number Diff line number Diff line change
Expand Up @@ -1163,30 +1163,19 @@
params.data = "" ;
}
let mySelect = $('#' + settings.id).data('select2');
if(settings.autocomplete && settings.multiple){
let searchField = document.querySelector('.select2-search--dropdown .select2-search__field');
params.data.q = searchField.value;
__cachekey = params.data.q;
} else {
params.data.q = mySelect.$container.find('input').val();
__cachekey = params.data.q;

}
if(settings.autocomplete){
if(settings.multiple){
let searchField = document.querySelector('.select2-search--dropdown .select2-search__field');
params.data.q = searchField.value;
}else{
params.data.q = mySelect.$container.find('input').val();
__cachekey = params.data.q;
}
}
if (__lastQuery !== __cachekey) {
// Verificar si existe un valor en __cache que coincida con __cachekey
if (__cache[""] && __cache[""].some(item => item.text === __cachekey)) {
// Si no existe coincidencia, limpiar el __cache
params.data.q = '';

} else {

if (__lastQuery !== "") {
delete __cache[__lastQuery];
}

}

}
// remove caches not from last query
__cache = [];
}
__lastQuery = __cachekey;
//Si esta cacheado, no busca
if (settings.cache == true && 'undefined' !== typeof __cache[__cachekey]) {
Expand Down

0 comments on commit faf9dd2

Please sign in to comment.