This commit is contained in:
KONE SOREL 2026-03-07 09:21:25 +00:00
parent f4cf1be505
commit ec5878d0f1
3 changed files with 18 additions and 38 deletions

View File

@ -47686,45 +47686,29 @@ function filtreVilleParPays() {
const racineWeb = $("#racineWeb").val();
const $divVille = $('#div_ville');
// 1. Si aucun pays n'est sélectionné, on peut vider ou griser la ville
if (!codePays || codePays === "") {
$divVille.find('select').html('<option value=""><?= _("Choisir d\'abord un pays") ?></option>').selectpicker('refresh');
return;
}
if (!codePays) return;
// 2. Feedback visuel de chargement sur le conteneur
$divVille.css('opacity', '0.5');
// 3. Appel AJAX
$.ajax({
url: racineWeb + "Ajaxfiltrevilleparpays/",
type: 'post',
data: { codePays: codePays }, // Passage en objet JSON (plus propre)
data: { codePays: codePays },
success: function(data) {
// 4. On vide et on injecte le nouveau <select> ou les nouvelles <option>
// 1. Détruire l'instance SelectPicker existante avant de vider le HTML
$divVille.find('.selectpicker').selectpicker('destroy');
// 2. Injecter le nouveau contenu
$divVille.html(data);
// 5. CRUCIAL : Ré-initialisation du SelectPicker
// Comme le contenu est dynamique, il faut dire au plugin de se reconstruire
setTimeout(function() {
const $selectVille = $divVille.find('select');
$selectVille.selectpicker({
liveSearch: true,
style: 'btn-white border-2 border-start-0 fw-bold',
size: 8
});
$selectVille.selectpicker('refresh');
}, 50);
if (typeof toastr !== 'undefined') {
toastr.info("Villes synchronisées");
}
},
error: function(xhr) {
console.error("Erreur filtrage ville :", xhr.statusText);
},
complete: function() {
$divVille.css('opacity', '1');
// 3. Ré-initialiser proprement le nouveau select
const $newSelect = $divVille.find('select');
$newSelect.addClass('selectpicker').selectpicker({
liveSearch: true,
style: 'btn-white border-2 border-start-0 fw-bold',
width: '100%'
});
// 4. Forcer le rafraîchissement final
$newSelect.selectpicker('refresh');
}
});
}

View File

@ -1,6 +1,3 @@
<select name="codeVille" id="codeVille"
class="form-select border-2 border-start-0 ps-0 selectpicker show-tick"
data-live-search="true"
required onchange="JAVASCRIPT:filtreLocaliteParVille();">
<?= liste_options($ville,'',false) ?>
<select name="codeVille" id="codeVille" class="form-select selectpicker" data-live-search="true" required onchange="filtreLocaliteParVille();">
<?= liste_options($villes, '', false) ?>
</select>

View File

@ -26,7 +26,6 @@
class="form-select border-2 border-start-0 ps-0 selectpicker show-tick"
data-live-search="true"
required onchange="filtreVilleParPays();">
<option value=""><?= _("Choisir un pays") ?></option>
<?= liste_options($pays,'',false) ?>
</select>
</div>