You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
public class PhoneNumber
{
public string Value { get; set; } = "";
public string Prefix { get; set; } = "";
}
public class PhoneValidator : AbstractValidator<PhoneNumber>
{
public PhoneValidator()
{
RuleFor(c => c.Value)
.NotEmpty().WithMessage("Telefonní číslo je povinné");
RuleFor(c => c.Prefix)
.NotEmpty().WithMessage("Předvolba je povinná");
RuleFor(c => c)
.Must(c => c.IsValid()).WithMessage("Neplatné telefonní číslo");
}
}
public abstract class ContactInputValidator<TContactInput> : AbstractValidator<TContactInput>
where TContactInput : IContactInput
{
public ContactInputValidator()
{
RuleFor(c => c.PhoneNumber)
.SetValidator(new PhoneValidator());
}
}
EditContext?.NotifyFieldChanged(_phoneNumberFieldIdentifier.Value); (_phoneNumberFieldIdentifier.Value because it's nullable)
and when I execute tha last line of provided code ValidationMessage for PhoneNumber shows messages for all 3 rules in PhoneNumberValidator. Why? When I validate form, only the correct message is displayed and I need to the same behavior with NotifyFieldChanged. Is it possible?
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
I have this code (just part of it)
_phoneNumberFieldIdentifier = EditContext.Field(nameof(PhoneNumber));
EditContext?.NotifyFieldChanged(_phoneNumberFieldIdentifier.Value);
(_phoneNumberFieldIdentifier.Value because it's nullable)and when I execute tha last line of provided code ValidationMessage for PhoneNumber shows messages for all 3 rules in PhoneNumberValidator. Why? When I validate form, only the correct message is displayed and I need to the same behavior with NotifyFieldChanged. Is it possible?
Beta Was this translation helpful? Give feedback.
All reactions