Choices-js / Choices

A vanilla JS customisable select box/text input plugin ⚡️
https://choices-js.github.io/Choices/
MIT License
6.05k stars 597 forks source link

Real time change choice text #1157

Open MarkoSh opened 1 month ago

MarkoSh commented 1 month ago

I have a select element where I change the text of an option. In normal time without a plugin this works fine just by using this piece of code:

option.text = ${ option.DEFAULT_TEXT }: fans ${ arr.length }${ total ?, spent $${ total }: '' };

When using the plugin I have to do destroy and init. Alternatively, I tried doing this:

choices._currentState.choices.map( ( choice: any ) => { choice.label = 'Changed'; // } );

But once applied, you have to select one of the items for the texts to change. It would be nice to get a tutorial on how to make the text change in real time something like this:

const choice = choices.getChoiceByValue( 'value_name' ); const customProperties = choice.customProperties; const DEFAULT_TEXT = customProperties.DEFAULT_TEXT; choices.setTextByValue( 'value_name', ${ DEFAULT_TEXT }: blablabla );

without reloading the element, but redraw it, even with dropdown

MarkoSh commented 1 month ago

image If it works - it's not stupid ))) It works cool as i want, just working on reset scroll position in dropdown, but looks cool in real time