Skip to content

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

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

Dhivya-SF4094
Copy link
Contributor

@Dhivya-SF4094 Dhivya-SF4094 commented Jul 10, 2025

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

  • Android
  • Windows
  • iOS
  • Mac

Issues Fixed:

Fixes #30181

Screenshots

Before  After 
 
30181_BeforeFix.mov
  
30181_AfterFix.mov

Copy link
Contributor

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.

@dotnet-policy-service dotnet-policy-service bot added community ✨ Community Contribution partner/syncfusion Issues / PR's with Syncfusion collaboration labels Jul 10, 2025
@Dhivya-SF4094 Dhivya-SF4094 marked this pull request as ready for review July 11, 2025 11:20
@Copilot Copilot AI review requested due to automatic review settings July 11, 2025 11:20
@Dhivya-SF4094 Dhivya-SF4094 requested a review from a team as a code owner July 11, 2025 11:20
Copy link
Contributor

@Copilot Copilot AI left a 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))
Copy link
Preview

Copilot AI Jul 11, 2025

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.

Suggested change
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
Copy link
Preview

Copilot AI Jul 11, 2025

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
community ✨ Community Contribution partner/syncfusion Issues / PR's with Syncfusion collaboration
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Entry bound to a double casts values too early, preventing small negative decimal entries
1 participant