If I have the following viemodel properties:
public class ExampleViewModel
{
[Required(ErrorMessage = "The email field is required.")]
[EmailAddress(ErrorMessage ="Please enter a valid email address")]
public string Email { get; set; }
[Required(ErrorMessage = "The first name field is required.")]
[RegularExpression("^[a-zA-Z\\-]+$", ErrorMessage="Please enter a valid name")]
public string Forename { get; set; }
[Required(ErrorMessage = "The last name field is required.")]
[RegularExpression("^[a-zA-Z\\-]+$", ErrorMessage = "Please enter a valid name")]
public string Surname { get; set; }
}
Then how do I only enable required fields on front-end ONLY after the fields are clicked on and clicked away from?
Currently the error messages are presented to the viewer straight away:
The front-end razor page is using blazorise validation, which only validates if all fields have been filled:
<Form method="post">
<Validations Mode="ValidationMode.Auto" Model="@ExampleViewModel" ValidatedAll="IsInvalid">
<Validation>
<Blazorise.Field>
<Blazorise.FieldLabel Class="is-bold">Email address</Blazorise.FieldLabel>
<Blazorise.TextEdit Placeholder="Enter email" @bind-Text="@ContactDetails.Email" MaxLength=40>
<Feedback>
<ValidationError />
</Feedback>
</Blazorise.TextEdit>
</Blazorise.Field>
</Validation>
<Row>
<Blazorise.Title Size="10">Your Details</Blazorise.Title>
</Row>
<Validation>
<Blazorise.Field>
<Blazorise.FieldLabel Class="is-bold">First name</Blazorise.FieldLabel>
<Blazorise.TextEdit Placeholder="John" @bind-Text="@ContactDetails.Forename" MaxLength=40>
<Feedback>
<ValidationError/>
</Feedback>
</Blazorise.TextEdit>
</Blazorise.Field>
</Validation>
<Validation>
<Blazorise.Field>
<Blazorise.FieldLabel Class="is-bold">Last name</Blazorise.FieldLabel>
<Blazorise.TextEdit Placeholder="Doe" @bind-Text="@ContactDetails.Surname" MaxLength=40>
<Feedback>
<ValidationError />
</Feedback>
</Blazorise.TextEdit>
</Blazorise.Field>
</Validation>