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

Selection controls do not function properly with SelectedValue of type bool? #1812

Open
OronDF343 opened this issue May 2, 2024 · 1 comment · May be fixed by #1816
Open

Selection controls do not function properly with SelectedValue of type bool? #1812

OronDF343 opened this issue May 2, 2024 · 1 comment · May be fixed by #1816
Labels

Comments

@OronDF343
Copy link
Contributor

dot:ComboBox, and probably any other controls that derive from Selector, do not support (nullable) boolean properties. Selecting the option with the value null behaves as expected, but selecting and other option will always set the value to true.

Using DotVVM.AspNetCore version 4.2.6 on net6.0.

Example code:

<div class="form-group" Validator.InvalidCssClass="has-error" Validator.Value="{value: Form.HasGenerator}">
    <label for="HasGenerator">Is there a generator?&nbsp;<span class="text-danger">*</span></label>
    <dot:ComboBox html:id="HasGenerator" SelectedValue="{value: Form.HasGenerator}" class="form-control">
        <dot:SelectorItem Text="Choose an option..." Value="{value: null}" />
        <dot:SelectorItem Text="No" Value="{value: false}" />
        <dot:SelectorItem Text="Yes" Value="{value: true}" />
    </dot:ComboBox>
</div>

When Choose an option... is selected, dotvvm.viewModels.root.viewModel.Form.state.HasGenerator evaluates to null. When any other option (Yes or No) is selected, dotvvm.viewModels.root.viewModel.Form.state.HasGenerator evaluates to true.

(I am using ComboBox instead of RadioButtons for accessibility reasons on mobile.)

@exyi exyi added the bug label May 2, 2024
exyi added a commit that referenced this issue May 7, 2024
* broken JS coercion from 'false' to boolean fixed
* SelectorItems renders all non-string values as `data-bind='value: value'`.
   Knockout.js then reads the value binding instead of the value attribute, so
   we avoid the roundtrip through strings

resolves  #1812
@exyi exyi linked a pull request May 7, 2024 that will close this issue
@exyi
Copy link
Member

exyi commented May 7, 2024

Thanks for the bug report. While fixing this, I found that it works when you bind the booleans through DataSource instead of the hardcoded SelectorItems. I think that you can use that as a workaround before we release the fix

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

Successfully merging a pull request may close this issue.

2 participants