FIXED
Instead of using ValidationResult? IsValid(object?, ValidationContext)
i just used
bool IsValid(object)
, and that seems to be working fine.
I've created a custom validation attribute for email, but it does not validate as it should.
Atm, i have set it to always fail, but somehow it still displays as if it was valid?
This is the class that is being used as the attribute, as you can see, it should be invalid no matter what.. (Or have i misunderstood)?
public class MailRegex : ValidationAttribute
{
protected override ValidationResult? IsValid(object? value, ValidationContext validationContext)
{
//if (RegexExpr.MailValidator(value.ToString()))
// return ValidationResult.Success;
return new ValidationResult(FormatErrorMessage(validationContext.DisplayName));
}
}
As you can see here, it gives the error as it should:
And this is when i press enter:
The property Test
is not being changed, when i submit (Which would mean that it isn't valid, right?)
It would mean that the input is not valid but is being displayed as a valid input which doens't make any sense.
<EditForm Model="s" OnValidSubmit='(() => Test = "asd")'>
<DataAnnotationsValidator />
<InputText placeholder="Mail" @bind-Value="s.Email"></InputText>
<ValidationMessage For="@(() => s.Email)" />
</EditForm>
@Test
@code {
public NewClass s { get; set; } = new();
public string Test = "Test string";
protected override void OnAfterRender(bool firstRender)
{
StateHasChanged();
}
}
I have tried to remove the validation, and make it fail on purpose (but still displays as valid).
I have not tried anything else really, beacuse i have no clue nor any idea how to fix this.