@@ -38,6 +38,12 @@ function optionRendering(data, container) {
3838 // Aggiunta degli attributi impostati staticamente
3939 selectOptionAttributes ( data ) ;
4040
41+ // Gestione delle opzioni disabilitate - solo attributi per CSS
42+ if ( ( data . element && $ ( data . element ) . prop ( 'disabled' ) ) || data . disabled ) {
43+ $ ( container ) . attr ( 'aria-disabled' , 'true' ) ;
44+ return data . text ;
45+ }
46+
4147 // Impostazione del colore dell'opzione
4248 let bg ;
4349 if ( data . _bgcolor_ ) {
@@ -250,6 +256,18 @@ function initStaticSelectInput(input) {
250256 templateResult : optionRendering ,
251257 templateSelection : selectionRendering ,
252258 } ) ;
259+
260+ // Previeni la selezione di opzioni disabilitate
261+ $input . on ( 'select2:selecting' , function ( e ) {
262+ if ( e . params && e . params . data && e . params . data . element ) {
263+ if ( $ ( e . params . data . element ) . prop ( 'disabled' ) ) {
264+ e . preventDefault ( ) ;
265+ return false ;
266+ }
267+ }
268+ } ) ;
269+
270+
253271}
254272
255273/**
@@ -319,6 +337,16 @@ function initDynamicSelectInput(input) {
319337 width : '100%'
320338 } ) ;
321339
340+ // Previeni la selezione di opzioni disabilitate per select AJAX
341+ $input . on ( 'select2:selecting' , function ( e ) {
342+ if ( e . params && e . params . data && e . params . data . disabled ) {
343+ e . preventDefault ( ) ;
344+ return false ;
345+ }
346+ } ) ;
347+
348+
349+
322350 // Rimozione delle option presenti nell'HTML per permettere l'aggiornamento dei dati via AJAX
323351 // Rimozione per select multipli
324352 if ( $input . prop ( "multiple" ) ) {
0 commit comments