Choices icon indicating copy to clipboard operation
Choices copied to clipboard

Set a value through javascript, without setValue()

Open augustomauro opened this issue 2 years ago • 1 comments

I need to set the values ​​as normal via document.getElementById('select').value = 2 and have it hit like a normal change event and have the Choice.js plugin recognize it perfectly and display it. I observe that the original select loses all the

document.querySelectorAll('select').forEach((select) = > {
                            selectChoices.push(new Choices(select, {
                                allowHTML: false,
                                silent: true,
                                placeholder: true,
                                placeholderValue: '',
                                searchPlaceholderValue: 'Ingrese texto',
                                loadingText: 'Cargando...',
                                noResultsText: 'No se encontraron resultados',
                                noChoicesText: 'No hay opciones para elegir',
                                itemSelectText: '',
                                searchFields: ['label'],    // por defecto ['label','value']. Para buscar solo sobre las etiquetas innerText y no los values del option
                                // searchFloor: 2,
                                shouldSort: false,
                                // Para mejorar la busqueda de matcheo (ref: https://github.com/Choices-js/Choices/issues/135)
                                fuseOptions: {
                                    threshold: 0.1,
                                    distance: 1000
                                }
                            })
});

Thanks !!

augustomauro avatar Mar 06 '22 23:03 augustomauro

@augustomauro, yes, that would also be a better solution for #277 @jshjohnson, doesn't Choices.js listen for change on the <select> element?

pecuchet avatar Apr 01 '22 17:04 pecuchet