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

Binding boolean field to a true/false select element #177

Closed
Feuerwerk opened this issue Jan 4, 2022 · 1 comment · Fixed by #406
Closed

Binding boolean field to a true/false select element #177

Feuerwerk opened this issue Jan 4, 2022 · 1 comment · Fixed by #406
Assignees
Labels
bug Something isn't working hilla Issues related to Hilla

Comments

@Feuerwerk
Copy link

Description of the bug

When binding a boolean field to a vaadin-select using the following construct

<vaadin-select ${field(model.mode)} .renderer="${guard([], () => (root: HTMLElement) => render(html`
   <vaadin-list-box>
      <vaadin-item value="true">Description Text A</vaadin-item>
      <vaadin-item value="false">Description Text B</vaadin-item>
   </vaadin-list-box>`, root))}">
</vaadin-select>

the used BooleanModel will interpret every string that is not empty as true since Boolean() is used to convert the string back to a boolean.
Changing the false-item to an empty string as suggested by @Haprog doesn't work either. Writing back into the model works but reading from the model will result in an empty select element.
Using a checkbox or radio buttons in this case is not a viable solution in my case since i have longer labels to describe the two options which would either confuse the user (checkbox) or waste ui space (radiobuttons)

Expected behavior

It is expected that if the property value is true option A of the select element is shown and if the value is false option B is shown.
When changing the select element to option A the property value should be change to true and if changed to option B the value should be false.

Actual behavior

When changing the select element to option A the property value will be set to true and if changed to option B the value is set to false. But when reading from the model the select element becomes empty for every property value.

Versions:

Vaadin 22.0.2
Java: 16

@Feuerwerk Feuerwerk added bug Something isn't working hilla Issues related to Hilla labels Jan 4, 2022
@haijian-vaadin
Copy link
Contributor

It's a bug in the BooleanModel fromString, we should fix that and possibly open a static property that users can override themselves to customize the behavior.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working hilla Issues related to Hilla
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants