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

Issue using bidir-value on a <select> when <option>s are added dynamically #54

Open
PokingUrsa opened this issue Oct 22, 2020 · 1 comment

Comments

@PokingUrsa
Copy link

PokingUrsa commented Oct 22, 2020

We recently encountered an issue with Flavour when trying to specify a 'select' element with dynamically-generated options:

<select html:bidir-value="selectedValue">
  <std:foreach var="item" in="items">
    <option attr:value="item.value"><html:text value="item.description"></option>
  </std:foreach>
</select>

The tricky part is that "items" is being loaded from the server, and isn't available during the first template update.

What happens is:

  • Pass 1
    • selectedValue is read, and bidir-value calls setValue on the select
    • items is empty, so there are no options in the select. setValue has no effect.
  • Pass 2
    • selectedValue is read, but is the same as before. The call to setValue is skipped (line 56 of BidirectionalValueBinder)
    • items is now populated from the server call. option elements get added to the select, but the right one isn't selected (since setValue was not called again).

Is there a clean solution to this?

@cyberquarks
Copy link

@PokingUrsa have you tried std:if condition?

Not sure if all EL is documented by I just usually use sourcegraph to find some examples from the repo:
https://sourcegraph.com/search?q=repo:%5Egithub%5C.com/konsoletyper/teavm-flavour%24+std:if&patternType=literal

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