dotvvm
dotvvm copied to clipboard
Selection controls do not function properly with SelectedValue of type `bool?`
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? <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 RadioButton
s for accessibility reasons on mobile.)
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
Fix is published on NuGet in 4.3.0-preview04-final.