-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Fixed Early casting in Entry bound to double for negative decimal input #30540
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
base: main
Are you sure you want to change the base?
Conversation
…l negative decimal entries
Hey there @@Dhivya-SF4094! Thank you so much for your PR! Someone from the team will get assigned to your PR shortly and we'll get it reviewed. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR addresses premature numeric conversion in an Entry bound to a double, ensuring users can type small negative decimal values without interruption.
- Adjusts the conversion logic to preserve raw strings starting with “0” or “-0” for decimal types.
- Adds a C#-based HostApp sample page demonstrating the scenario.
- Introduces a UI test that verifies typing
-0.01
is retained correctly.
Reviewed Changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.
File | Description |
---|---|
src/Controls/src/Core/BindingExpressionHelper.cs | Expanded the leading-zero check to include strings starting with 0 |
src/Controls/tests/TestCases.HostApp/Issues/Issue30181.cs | Added a code-only ContentPage to host the numeric Entry sample |
src/Controls/tests/TestCases.Shared.Tests/Tests/Issues/Issue30181.cs | Added a UITest checking small negative decimal input is preserved |
Comments suppressed due to low confidence (1)
src/Controls/tests/TestCases.Shared.Tests/Tests/Issues/Issue30181.cs:16
- Consider adding a test case for positive small decimal inputs (e.g., "0.01") to ensure the updated condition also preserves positive leading zeros.
public void EntryBoundToDouble_AllowsTypingSmallNegativeDecimal()
@@ -38,7 +38,7 @@ internal static bool TryConvert(ref object value, BindableProperty targetPropert | |||
} | |||
|
|||
// do not canonicalize "-0"; user will likely enter a period after "-0" | |||
if (stringValue == "-0" && DecimalTypes.Contains(convertTo)) | |||
if ((stringValue.StartsWith("0") || stringValue.StartsWith("-0")) && DecimalTypes.Contains(convertTo)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[nitpick] The condition using StartsWith("0") also matches strings like "01" or "00.5"; consider restricting it to precise patterns such as stringValue == "0" or stringValue.StartsWith("0.") to avoid unintended suppression of conversions.
if ((stringValue.StartsWith("0") || stringValue.StartsWith("-0")) && DecimalTypes.Contains(convertTo)) | |
if ((stringValue == "0" || stringValue.StartsWith("0.") || stringValue.StartsWith("-0")) && DecimalTypes.Contains(convertTo)) |
Copilot uses AI. Check for mistakes.
namespace Maui.Controls.Sample.Issues; | ||
|
||
[Issue(IssueTracker.Github, 30181, "Entry bound to a double casts values too early, preventing small negative decimal entries", PlatformAffected.All)] | ||
public class Issue30181 : ContentPage |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The HostApp UI test page is defined in C# only; per test harness guidelines, consider using a XAML file (Issue30181.xaml) and code-behind (Issue30181.xaml.cs) for consistency with other UI tests.
Copilot uses AI. Check for mistakes.
Note
Are you waiting for the changes in this PR to be merged?
It would be very helpful if you could test the resulting artifacts from this PR and let us know in a comment if this change resolves your issue. Thank you!
Issue Detail
When using a numeric Entry bound to a double, entering small negative is not handled correctly due to premature value conversion.
Root Cause
The issue was caused by the logic relying on the parsed numeric value (double) rather than preserving the raw string input
Description of Change
To address this, the logic was updated to preserve input strings that begin with "0" or "-0" for decimal types. This prevents premature type conversion during user input and allows the full value to be typed correctly without interference.
Validated the behaviour in the following platforms
Issues Fixed:
Fixes #30181
Screenshots
30181_BeforeFix.mov
30181_AfterFix.mov