Skip to content

trying to understand how callbackOnCreateTemplates works #1292

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

Open
frumbert opened this issue Mar 27, 2025 · 1 comment
Open

trying to understand how callbackOnCreateTemplates works #1292

frumbert opened this issue Mar 27, 2025 · 1 comment

Comments

@frumbert
Copy link

I am new to choicesjs and just trying it out, late at night, and I am probably missing something obvious.

I just want to modify the choice so that it shows extra custom property values after the label (e.g. item code, description, etc, with a bit of html formatting).

i tried copy-pasting the "more complex" example from the readme into my code and it throws the error template is not defined or similar - i don't know what 'template' refers to in the example code.

The first example under callbackOnCreateTemplates is similarly confusing, as the description mentions 'If you want just extend a little original template then you may use Choices.defaults.templates to get access to original template function' and then fails to describe how. Copy-pasting that also throws an error.

I checked stackoverflow and asked chatgpt for examples, but the responses seem to be for a totally different version as they aren't remotely like the example code in the readme.

@Xon
Copy link
Collaborator

Xon commented Apr 3, 2025

callbackOnCreateTemplates is a function which returns an list of name/functions pairs for creating various templates. Choices.defaults.templates is just the default implementation which can be easily invoked and then you can modify the returned HTML

I'ld recommend posting a jsfiddle version of what you are trying.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants