dotvvm icon indicating copy to clipboard operation
dotvvm copied to clipboard

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

Open OronDF343 opened this issue 9 months ago • 1 comments

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.)

OronDF343 avatar May 02 '24 08:05 OronDF343

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

exyi avatar May 07 '24 18:05 exyi

Fix is published on NuGet in 4.3.0-preview04-final.

exyi avatar Jun 08 '24 22:06 exyi