-
Notifications
You must be signed in to change notification settings - Fork 10.4k
Binding support for 'bool' values with InputRadioGroup and InputSelect #35318
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
Changes from 3 commits
bfcb5dd
ed26d0a
b3e6f73
1c0701e
3ff96df
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -70,6 +70,14 @@ | |
</InputSelect> | ||
<span>@string.Join(", ", person.HostileStrings)</span> | ||
</p> | ||
<p class="select-bool-values"> | ||
T/F: 77 + 33 = 100<br> | ||
<InputSelect @bind-Value="person.IsSelectMathStatementTrue"> | ||
<option>(select)</option> | ||
<option value="true">true</option> | ||
<option value="false">false</option> | ||
</InputSelect> | ||
</p> | ||
<p class="airline"> | ||
<InputRadioGroup @bind-Value="person.Airline"> | ||
Airline: | ||
|
@@ -96,6 +104,13 @@ | |
</InputRadioGroup> | ||
</InputRadioGroup> | ||
</p> | ||
<p class="radio-group-bool-values"> | ||
T/F: 7 * 3 = 21<br> | ||
<InputRadioGroup @bind-Value="person.IsRadioMathStatementTrue"> | ||
<InputRadio Value="true" />true<br> | ||
<InputRadio Value="false" />false<br> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm guessing that if the code here was If I'm reading the code here correctly, I think it doesn't make any difference because the binding machinery is really on the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Since That said, the <InputSelect @bind-Value="ignoreTheTypeOfThis">
<!-- We can set the value attribute to an enum, because the bind formatter properly serializes it -->
<option value="@SomeEnum.Choice">Choice</option> <!-- Good -->
<!-- But we can't do this with a bool, because now 'value' is treated as a conditional attribute -->
<option value="@true">true</option> <!-- Bad! -->
<!-- So, we have to use a string -->
<option value="true">true</option> <!-- Good? -->
</InputSelect> |
||
</InputRadioGroup> | ||
</p> | ||
<p class="socks"> | ||
Socks color: <InputText @bind-Value="person.SocksColor" /> | ||
</p> | ||
|
@@ -188,6 +203,12 @@ | |
[Required, EnumDataType(typeof(Country))] | ||
public Country? Country { get; set; } = null; | ||
|
||
[Required, Range(typeof(bool), "false", "false", ErrorMessage = "77 + 33 = 100 is a false statement, unfortunately.")] | ||
public bool? IsSelectMathStatementTrue { get; set; } = null; | ||
|
||
[Required, Range(typeof(bool), "true", "true", ErrorMessage = "7 * 3 = 21 is a true statement.")] | ||
public bool IsRadioMathStatementTrue { get; set; } = false; | ||
|
||
[Required, StringLength(10), CustomValidationClassName(Valid = "valid-socks", Invalid = "invalid-socks")] | ||
public string SocksColor { get; set; } | ||
|
||
|
Uh oh!
There was an error while loading. Please reload this page.