Skip to content
This repository has been archived by the owner on May 1, 2024. It is now read-only.

[Bug] NumericValidationBehavior throws an exception #1988

Open
mmiller-d8 opened this issue Oct 4, 2023 · 3 comments
Open

[Bug] NumericValidationBehavior throws an exception #1988

mmiller-d8 opened this issue Oct 4, 2023 · 3 comments
Labels
bug Something isn't working. Breaky break.

Comments

@mmiller-d8
Copy link

mmiller-d8 commented Oct 4, 2023

Description

I had this in the wrong area, so I'm moving it here. #1984 Although, I'm starting to wonder if anyone is actually triaging these.

Edit: Apparently, I can't add a label for the area.

Anyways...

In the Maui Community Tookit, the NumericValidationBehavior throws an exception if the entry field is empty.

Looking at the source, the first line in ValidateAsync throws an ArgumentNullException if the value is null. Unless I’m missing something, there’s no way to catch that and it crashes the app.

It should just return false. Ideally, there would be an IsRequired property that would allow it to return true if the value was null or empty.

Steps to Reproduce

  1. Create a page with an entry field.
  2. Add a NumericValidationBehavior and set the validation behavior to on lose focus
  3. Tap the entry field and then tap something else to take way it's focus
  4. Boom. It crashes the app

Expected Behavior

You can leave a field empty without crashing the app

Actual Behavior

It crashes the app

Basic Information

  • Version with issue: 5.3.0
  • Last known good version: n/a
  • IDE: Visual Studio for Mac
  • Platform Target Frameworks:
    • iOS: 16.1
    • Android: 13
    • Windows: n/a
  • Nuget Packages:
  • Affected Devices: All

Workaround

No. I downloaded the source and created a local version with the change.

@mmiller-d8 mmiller-d8 added the bug Something isn't working. Breaky break. label Oct 4, 2023
@bijington
Copy link
Contributor

You actually want this repo: https://github.com/CommunityToolkit/Maui

That being said our documentation explains how to avoid this:

https://learn.microsoft.com/dotnet/communitytoolkit/maui/get-started?tabs=CommunityToolkitMaui#using-the-nuget-packages

@mmiller-d8
Copy link
Author

Thanks.

So, I have to turn off all exceptions in all behaviors to avoid one issue? My opinion still stands that it is a poor design choice and should be changed.

@bijington
Copy link
Contributor

That is currently the case yes. I would add that the exceptions being thrown typically only relate to whether you want to safely handle nulls as a default value.

Feel free to open a discussion on the repository if you feel you have something to propose as a change

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Something isn't working. Breaky break.
Projects
None yet
Development

No branches or pull requests

2 participants