kbrsh / moon

🌙 The minimal & fast library for functional user interfaces
https://moonjs.org
MIT License
5.99k stars 200 forks source link

Interpolation does not work within HTML attributes #243

Closed dustincleveland closed 5 years ago

dustincleveland commented 5 years ago
<div For={$x,$index in fitData}>
    <h5>{$x}</h5>

    {$index}

    <select
        id="Form_{$index}_Value"
        name="Form[{$index}].Value"
        class="form-control {$index}">
        ...

In the example above, {$x} and the first instance of {$index} will be rendered. However, none of the {$index} bindings in the select element's attributes will be rendered. Instead, the HTML that is rendered ends up being Form[{$index}].Value.

kbrsh commented 5 years ago

Moon v1 only supports dynamic attributes with the key={value} syntax. However, I am open to changing this to support the previous syntax given enough support.

dustincleveland commented 5 years ago

My mistake then. I must have seen that interpolation worked in text elements and assumed that it would work in attributes as well. This is a pretty common feature of most view binding engines I've encountered, so I'd definitely recommend it. But, at the very least, it may be helpful to add a note about this to your documentation on your website.

kbrsh commented 5 years ago

This change will require a significant amount of extra weight to the compiler, and I think that the utility it provides isn't worth it. In addition, libraries like Vue don't support it either. Closing for now but I may consider it if there is enough support for the idea.