This commit is contained in:
KONE SOREL 2026-03-07 11:12:17 +00:00
parent 3793f91b98
commit 23302a299e
3 changed files with 34 additions and 38 deletions

View File

@ -47682,41 +47682,19 @@ function formAjoutTableRef() {
// Filtrer la liste des villes par pays // Filtrer la liste des villes par pays
function filtreVilleParPays() { function filtreVilleParPays() {
const codePays = $('#codePays').val(); const $selectVille = $('#codeVille');
const racineWeb = $("#racineWeb").val();
const $divVille = $('#div_ville');
if (!codePays) return;
$.ajax({ $.ajax({
url: racineWeb + "Ajaxfiltrevilleparpays/", url: $("#racineWeb").val() + "Ajaxfiltrevilleparpays/",
type: 'post', type: 'post',
data: { codePays: codePays }, data: { codePays: $('#codePays').val() },
beforeSend: function() { success: function(htmlOptions) {
// Étape 1 : Détruire le plugin sur l'ancien select pour éviter les doublons visuels // On change les options
$divVille.find('.selectpicker').selectpicker('destroy'); $selectVille.html(htmlOptions);
$divVille.css('opacity', '0.5');
},
success: function(data) {
// Étape 2 : Remplacer le contenu HTML (le nouveau <select> arrive du PHP)
$divVille.html(data);
// Étape 3 : Identifier le nouveau select et le reconstruire proprement
const $newSelect = $divVille.find('select');
// On s'assure qu'il a les bonnes classes // ON APPELLE TA FONCTION : elle verra que le select existe déjà
$newSelect.addClass('form-control selectpicker').selectpicker({ // et fera un 'refresh' proprement sans doubler le texte.
liveSearch: true, actualiserSelectPicker('#codeVille');
style: 'btn-white border-2 border-start-0 fw-bold',
width: '100%',
size: 8
});
// Étape 4 : Rafraîchissement forcé
$newSelect.selectpicker('refresh');
},
complete: function() {
$divVille.css('opacity', '1');
} }
}); });
} }
@ -91657,3 +91635,23 @@ function initDataTableReference(selector, exportTitle = 'Export_Donnees') {
table.buttons().container().appendTo('#table-buttons'); table.buttons().container().appendTo('#table-buttons');
return table; return table;
} }
function actualiserSelectPicker(selector) {
$(selector).each(function() {
const $el = $(this);
// TEST DE SÉCURITÉ : Si le plugin n'est pas là, on l'installe
if (!$el.data('selectpicker')) {
$el.selectpicker({
liveSearch: true,
style: 'btn-white border-2 border-start-0 fw-bold',
width: '100%',
size: 8,
noneSelectedText: $("#codeLangue").val() === 'en_US' ? '-- Select --' : '-- Sélectionner --'
});
} else {
// S'il est déjà là, on rafraîchit juste les données
$el.selectpicker('refresh');
}
});
}

View File

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

View File

@ -39,7 +39,8 @@
<span class="input-group-text bg-light border-2 border-end-0"><i class="fas fa-city text-muted"></i></span> <span class="input-group-text bg-light border-2 border-end-0"><i class="fas fa-city text-muted"></i></span>
<select name="codeVille" id="codeVille" <select name="codeVille" id="codeVille"
class="form-control border-2 border-start-0 ps-0 selectpicker" class="form-control border-2 border-start-0 ps-0 selectpicker"
data-live-search="true" required> data-live-search="true"
required onchange="JAVASCRIPT:filtreLocaliteParVille();">
<?= liste_options($ville, $localite['codeVille'] ?? '', false) ?> <?= liste_options($ville, $localite['codeVille'] ?? '', false) ?>
</select> </select>
</div> </div>