Skip to content

Fix globalization for @bind-value #12654

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

Merged
merged 1 commit into from
Jul 30, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@ namespace Microsoft.AspNetCore.Components
[Microsoft.AspNetCore.Components.BindElementAttribute("select", null, "value", "onchange")]
[Microsoft.AspNetCore.Components.BindElementAttribute("textarea", null, "value", "onchange")]
[Microsoft.AspNetCore.Components.BindInputElementAttribute("checkbox", null, "checked", "onchange", false, null)]
[Microsoft.AspNetCore.Components.BindInputElementAttribute("date", "value", "value", "onchange", true, "yyyy-MM-dd")]
[Microsoft.AspNetCore.Components.BindInputElementAttribute("date", null, "value", "onchange", true, "yyyy-MM-dd")]
[Microsoft.AspNetCore.Components.BindInputElementAttribute("number", "value", "value", "onchange", true, null)]
[Microsoft.AspNetCore.Components.BindInputElementAttribute("number", null, "value", "onchange", true, null)]
[Microsoft.AspNetCore.Components.BindInputElementAttribute("text", null, "value", "onchange", false, null)]
[Microsoft.AspNetCore.Components.BindInputElementAttribute(null, "value", "value", "onchange", false, null)]
Expand Down
2 changes: 2 additions & 0 deletions src/Components/Web/src/BindAttributes.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,11 @@ namespace Microsoft.AspNetCore.Components

// type="number" is invariant culture
[BindInputElement("number", null, "value", "onchange", isInvariantCulture: true, format: null)]
[BindInputElement("number", "value", "value", "onchange", isInvariantCulture: true, format: null)]

// type="date" is invariant culture with a specific format
[BindInputElement("date", null, "value", "onchange", isInvariantCulture: true, format: "yyyy-MM-dd")]
[BindInputElement("date", "value", "value", "onchange", isInvariantCulture: true, format: "yyyy-MM-dd")]

[BindElement("select", null, "value", "onchange")]
[BindElement("textarea", null, "value", "onchange")]
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<h3 id="bind-cases">Bind cases</h3>

@* There are a mix of cases here using bind and bind-value for coverage *@

<h2>Textbox</h2>
<p>
Initially blank:
Expand Down Expand Up @@ -32,7 +34,7 @@
</p>
<p>
Nullable int:
<input id="textbox-nullable-int" @bind="textboxNullableIntValue" type="number" />
<input id="textbox-nullable-int" @bind-value="textboxNullableIntValue" type="number" />
<span id="textbox-nullable-int-value">@textboxNullableIntValue</span>
<input id="textbox-nullable-int-mirror" @bind="textboxNullableIntValue" readonly />
</p>
Expand All @@ -50,7 +52,7 @@
</p>
<p>
float:
<input id="textbox-float" @bind="textboxFloatValue" type="number" />
<input id="textbox-float" @bind-value="textboxFloatValue" type="number" />
<span id="textbox-float-value">@textboxFloatValue</span>
<input id="textbox-float-mirror" @bind="textboxFloatValue" readonly />
</p>
Expand All @@ -74,7 +76,7 @@
</p>
<p>
decimal:
<input id="textbox-decimal" @bind="textboxDecimalValue" type="number" />
<input id="textbox-decimal" @bind-value="textboxDecimalValue" type="number" />
<span id="textbox-decimal-value">@textboxDecimalValue</span>
<input id="textbox-decimal-mirror" @bind="textboxDecimalValue" readonly />
</p>
Expand Down Expand Up @@ -119,7 +121,7 @@
</p>
<p>
Nullable DateTime:
<input id="textbox-nullable-datetime" @bind="textboxNullableDateTimeValue" type="text" />
<input id="textbox-nullable-datetime" @bind-value="textboxNullableDateTimeValue" type="text" />
<span id="textbox-nullable-datetime-value">@textboxNullableDateTimeValue</span>
<input id="textbox-nullable-datetime-mirror" @bind="textboxNullableDateTimeValue" readonly />
</p>
Expand Down Expand Up @@ -149,7 +151,7 @@
</p>
<p>
DateTime (format):
<input id="textbox-datetime-format" @bind="textboxDateTimeFormatValue" type="text" @bind:format="MM-dd" />
<input id="textbox-datetime-format" @bind-value="textboxDateTimeFormatValue" type="text" @bind-value:format="MM-dd" />
<span id="textbox-datetime-format-value">@textboxDateTimeFormatValue</span>
<input id="textbox-datetime-format-mirror" @bind="textboxDateTimeFormatValue" readonly />
</p>
Expand All @@ -161,7 +163,7 @@
</p>
<p>
DateTime (format / invalid value):
<input id="textbox-datetime-format-invalid" @bind="textboxDateTimeFormatInvalidValue" type="text" @bind:format="MM-dd" />
<input id="textbox-datetime-format-invalid" @bind-value="textboxDateTimeFormatInvalidValue" type="text" @bind-value:format="MM-dd" />
<span id="textbox-datetime-format-invalid-value">@textboxDateTimeFormatInvalidValue</span>
<input id="textbox-datetime-format-invalid-mirror" @bind="textboxDateTimeFormatInvalidValue" readonly />
</p>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,16 @@
<h3 id="globalization-cases">Globalization Bind Cases</h3>
<h3 id="culture-name-display">Culture is: @System.Globalization.CultureInfo.CurrentCulture.Name</h3>

@* There are a mix of cases here using bind and bind-value for coverage *@

<div>
<p>Numbers using bind in text fields</p>
<div>
int: <input type="text" id="input_type_text_int" @bind="inputTypeTextInt" />
<span id="input_type_text_int_value">@inputTypeTextInt</span>
</div>
<div>
decimal: <input type="text" id="input_type_text_decimal" @bind="inputTypeTextDecimal" />
decimal: <input type="text" id="input_type_text_decimal" @bind-value="inputTypeTextDecimal" />
<span id="input_type_text_decimal_value">@inputTypeTextDecimal</span>
</div>
</div>
Expand All @@ -22,7 +24,7 @@
<span id="input_type_text_datetime_value">@inputTypeTextDateTime</span>
</div>
<div>
DateTimeOffset: <input type="text" id="input_type_text_datetimeoffset" @bind="inputTypeTextDateTimeOffset" />
DateTimeOffset: <input type="text" id="input_type_text_datetimeoffset" @bind-value="inputTypeTextDateTimeOffset" />
<span id="input_type_text_datetimeoffset_value">@inputTypeTextDateTimeOffset</span>
</div>
</div>
Expand All @@ -34,7 +36,7 @@
<span id="input_type_number_int_value">@inputTypeNumberInt</span>
</div>
<div>
decimal: <input type="number" id="input_type_number_decimal" @bind="inputTypeNumberDecimal" />
decimal: <input type="number" id="input_type_number_decimal" @bind-value="inputTypeNumberDecimal" />
<span id="input_type_number_decimal_value">@inputTypeNumberDecimal</span>
</div>
</div>
Expand All @@ -47,7 +49,7 @@
<span id="input_type_date_datetime_value">@inputTypeDateDateTime</span>
</div>
<div>
DateTimeOffset: <input type="text" id="input_type_date_datetimeoffset_extrainput" @bind="inputTypeDateDateTimeOffset" />
DateTimeOffset: <input type="text" id="input_type_date_datetimeoffset_extrainput" @bind-value="inputTypeDateDateTimeOffset" />
<input type="date" id="input_type_date_datetimeoffset" @bind="inputTypeDateDateTimeOffset" />
<span id="input_type_date_datetimeoffset_value">@inputTypeDateDateTimeOffset</span>
</div>
Expand Down