1 pièce(s) jointe(s)
Input checked de même identifiant ajax
Bonjour,
J'utilise Bootstrap et js pour activer/désactiver la publication d'article ou bien la mise en avant et je rencontre un conflit:
1/ Je peux activer/désactiver sans problème si je mets en commentaire mon deuxième script pour la mise en avant des articles et donc seulement si mon premier script pour la publication est actif.
2/ Si j'utilise les 2 en même temps cela ne fonctionnent pas pour la mise en avant et de façon aléatoire pour la publication.
Je m'aperçois dans l'inspecteur que l'identification est la même pour mes 2 cases à cocher et je ne sais pas pourquoi alors, si vous pouviez me mettre sur la voie, je vous remercie d'avance.
Script 1:
Code:
1 2 3 4 5 6 7 8 9 10 11
|
// ACTIVATION EN AVANT (portcategory)
let activerPC = document.querySelectorAll("#pc")
for(let boutonPC of activerPC){
boutonPC.addEventListener("click", function(){
let xmlhttpPC = new XMLHttpRequest;
xmlhttpPC.open("get", `/admin/article/activer/${this.dataset.pc}`)
xmlhttpPC.send()
})
} |
Script 2:
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
|
// ACTIVATION PUBLISHED
window.onload = () => {
let activerPB = document.querySelectorAll("#pb")
for(let boutonPB of activerPB){
boutonPB.addEventListener("click", function(){
let xmlhttpPB = new XMLHttpRequest;
xmlhttpPB.open("get", `/admin/article/activer/${this.dataset.pb}`)
xmlhttpPB.send()
})
}
} |
Code:
1 2 3 4 5 6 7
|
<td class="tdAdmin text-center" data-title="Publié">
<input id="pb" class="text-center form-check-input" type="checkbox" {{ (article.published) ? 'checked' : '' }} data-pb="{{ article.id }}" role="switch">
</td>
<td class="tdAdmin text-center" data-title="En avant">
<input id="pc" class="text-center form-check-input" type="checkbox" {{ (article.portcategory) ? 'checked' : '' }} data-pc="{{ article.id }}" role="switch">
</td> |
Pièce jointe 611937