Option templateSelection via attributs HTML data
Select2 permet de personnaliser le markup des résultats sélectionnés avec l'option templateSelection
, cf. https://select2.org/selections#templating
Pour référence, ça fonctionne bien avec le script select2.js
de base, ma fonction de callback est bien appelée.
Exemple : je désactive le chargement des scripts dans le public, je charge manuellement le script select2.js
, et j'initialise ainsi :
jQuery('select.select2').select2({
templateSelection: mon_callback
});
Mais au final je souhaite garder la méthode du plugin : avoir ses scripts chargés dans le public, et contrôler au cas-par-cas au moyen des attributs data. Mais là c'est le fail, ça me retourne une erreur.
Dans le fork le callback se comporterait différemment ? J'avoue que je vois pas trop où chercher, des pistes ?
<select class="select2" data-template-selection="mon_callback">
Uncaught TypeError: template is not a function
display .../plugins/select2/javascript/select2.fork.full.js?1713990309:1757
update .../plugins/select2/javascript/select2.fork.full.js?1713990309:1785
update .../plugins/select2/javascript/select2.fork.full.js?1713990309:1845
calledMethod .../plugins/select2/javascript/select2.fork.full.js?1713990309:598
update .../plugins/select2/javascript/select2.fork.full.js?1713990309:1950
calledMethod .../plugins/select2/javascript/select2.fork.full.js?1713990309:598
update .../plugins/select2/javascript/select2.fork.full.js?1713990309:2156
calledMethod .../plugins/select2/javascript/select2.fork.full.js?1713990309:598
bind .../plugins/select2/javascript/select2.fork.full.js?1713990309:1470
invoke .../plugins/select2/javascript/select2.fork.full.js?1713990309:655
trigger .../plugins/select2/javascript/select2.fork.full.js?1713990309:645
trigger .../plugins/select2/javascript/select2.fork.full.js?1713990309:5830
Select2 .../plugins/select2/javascript/select2.fork.full.js?1713990309:5432
current .../plugins/select2/javascript/select2.fork.full.js?1713990309:3213
Select2 .../plugins/select2/javascript/select2.fork.full.js?1713990309:5431
select2 .../plugins/select2/javascript/select2.fork.full.js?1713990309:6765
jQuery 2
select2 .../plugins/select2/javascript/select2.fork.full.js?1713990309:6762
on_select .../plugins/select2/javascript/SpipSelect2.js?1713990768:115
on_select .../plugins/select2/javascript/SpipSelect2Loader.js?1711622298:9
on_select .../plugins/select2/javascript/SpipSelect2Loader.js?1711622298:9
load .../plugins/select2/javascript/SpipSelect2Loader.js?1711622298:31
onReady .../plugins/select2/javascript/SpipSelect2Loader.js?1711622298:26
<anonymous> .../plugins/select2/javascript/SpipSelect2Loader.js?1711622298:36