Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update choice label text function #1157

Open
MarkoSh opened this issue May 26, 2024 · 2 comments
Open

Update choice label text function #1157

MarkoSh opened this issue May 26, 2024 · 2 comments
Assignees

Comments

@MarkoSh
Copy link

MarkoSh commented May 26, 2024

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
Copy link
Author

MarkoSh commented May 26, 2024

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

@Xon Xon changed the title Real time change choice text Update choice label text function Aug 9, 2024
@Xon
Copy link
Collaborator

Xon commented Aug 22, 2024

@MarkoSh you will want to use choices._store.choices not choices._currentstate.choices for compatibility with v11.0.0.

I've prototyped up an Choices.updateLabel command but I'm still working on finishing off v11.0.0, with a primary focus on bugfix and performance fixes.

@Xon Xon self-assigned this Sep 11, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants