Skip to content

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

@fplagamba

Description

@fplagamba

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions