CommunityToolkit / CommunityToolkit/MVVM-Samples

Did I find a problem or did I not understand correctly? (Validation with Annotations)

Open
#126 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
No language data
Stars
1.4k
Forks
265
PR merge metrics
No merged PRs in 30d

Description

Hi Community,
I am testing CommunityToolkit.mvvm and I have some problems ...
#1
I have a property of type string that must contain an EmailAddrtes

This is the property definition:
[ObservableProperty]
[NotifyDataErrorInfo]
[Required]
[EmailAddress]
public string? _mailAddress;

This is working perfectly

But I also have a string property that should contain a date, but I can't get the correct validation.

This is the definition:
[ObservableProperty]
[NotifyDataErrorInfo]
[Required]
[DataType(DataType.DateTime)] // Doesn't work
[DisplayFormat(DataFormatString = "{0:yyyy-MM-dd}", ApplyFormatInEditMode = true)] // Doesn't work
public string? _birthDate2;

I think the problem is in the annotation:
[DataType(DataType.DateTime)]

But what do I have to write to get the correct validation?

#2
In addition to validation, I would also like to get the required formatting,
but that doesn't seem to work either.

#3
A general problem, not specifically of the toolkit.
When I search for something on GitHub / NuGet I find dozens of occurrences of packages of similar name...
Wouldn't it be appropriate to assign a unique identifier so that the poor programmer knows which one to choose?
Thank you for your attention.

Best regards

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.