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

Top-level data-link="{for...}" does not work on a 'select' element #456

Closed
alnico2001 opened this issue May 24, 2023 · 3 comments
Closed

Comments

@alnico2001
Copy link

If you replace <select> with a <div>, it renders fine.

https://jsfiddle.net/alnico/ubLzcxy7

@BorisMoore
Copy link
Owner

BorisMoore commented May 26, 2023

In your scenario you are wanting to data-link the innerHTML of a <select> - which is a different 'target' than the default value. See this section for discussion of multiple targets: Full syntax – multiple targets, multiple tags, multiple bindings...

So you need to use the target html{...}, for innerHTML . You can at the same time bind to value property, which is the default target for a <select> element. So you will have something like:

<select data-link="html{for selectOptions tmpl='nameTmpl'} {:chosenOption:}"></select>

using the data:

var appData = {
    chosenOption:"Option 2",
    selectOptions: [{ option: "Option 1" }, { option: "Option 2" }],
};

Here is an updated version of your JsFiddle: https://jsfiddle.net/BorisMoore/g26dzp4a/2/

See also Data-linking to innerText / innerHTML
as well as the related sample using the jQueryUI {{selectMenu}} control (second sample in the page)

@alnico2001
Copy link
Author

Ah yes, I should have caught that...1st time doing top-level data linking.
Thanks Boris!

@BorisMoore
Copy link
Owner

BTW, the same syntax for multiple targets, and the html{} target for <select> apply equally to regular linked template binding, as well as top-level binding.

see: https://jsfiddle.net/BorisMoore/vjz8f5h0/

Closing as "question" (not a bug)

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