const itemsSearchBox = [{id_item:'#select2CategorieMadri', value_item: ''}, {id_item:'#select2Province', value_item: ''}, {id_item:'#textRicercaArtigiani', value_item: ''}]; const selectIndices = ['#select2CategorieMadri', '#select2Province']; function getItemsValuesSearchBox(){ itemsSearchBox.forEach(itemIndex => { itemIndex.value_item = $(`${itemIndex.id_item}`).val(); }); } function settingsIcons(el){ $("#"+el.data('btn-remove')).removeClass('d-none'); $("#"+el.data('btn-remove')).addClass('trash-custom'); $("#"+el.data('btn-remove')).addClass('js-trigger-search-box'); $("#"+el.data('id-icon')).addClass('d-none'); } function asyncSearchBox(callAsyncSearchBox, el){ if(callAsyncSearchBox) { $.ajax({ url: 'https://www.ilcercartigianodiqualita.it/assets/ajax/async.search.box.php', type: 'POST', data: {'items_search_box': JSON.stringify(itemsSearchBox)}, dataType: 'json', beforeSend: function () { $('#btnRicercaArtigiani') .html('LABELS_RICERCA...   '); $('#containerResultsSearchBox').css('opacity', '0.3'); }, success: function (response) { if (response.status == 'success') { let html = response.html; $('#btnRicercaArtigiani').html('LABELS_CERCA'); $('#containerResultsSearchBox').css('opacity', '1'); $('#containerResultsSearchBox').html(html); if (response.elenco == 'elenco_artigiani') { $('.titleSearchBox').html("LABELS_ELENCO_AZIENDE"); $('.titleSearchBoxNomeCategoria').html(''); } else if (response.elenco == 'elenco_sottocategorie') { $('.titleSearchBox').html("LABELS_SEI_NELLA_PAGINA_CATEGORIE_ATTIVITA_DEL_SETTORE:"); $('.titleSearchBoxNomeCategoria').html(response.elenco_categorie); } else if ('elenco_categorie'){ $('.titleSearchBox').html("LABELS_SEI_NELLA_PAGINA_CATEGORIE_ATTIVITA"); $('.titleSearchBoxNomeCategoria').html(''); } settingsIcons(el); } else if (response.status == 'no-results') { settingsIcons(el); $('#btnRicercaArtigiani').html('LABELS_CERCA'); $('#containerResultsSearchBox').css('opacity', '1'); $('#containerResultsSearchBox').html('
LABELS_NESSUN_RISULTATO
'); } }, error: function (xhr, status, error) { console.error('Errore AJAX:', error); } }); } } selectIndices.forEach(index => { const $select = $(`select${index}`).select2(); $select.on('change', function (e) { /** * Automatic Event or Manually Event */ let callAsyncSearchBox = ''; if(event){ callAsyncSearchBox = event.isTrusted; } else { callAsyncSearchBox = false; } getItemsValuesSearchBox(); asyncSearchBox(callAsyncSearchBox, $(this)); }); });