I have a simple Razor page view with the following form fields:
<div class="col-sm-6">
<label asp-for="Input.FirstName" class="form-label"></label>
<input asp-for="Input.FirstName" class="form-control" autocomplete="first-name">
<span asp-validation-for="Input.FirstName" class="invalid-feedback" style="display:block"></span>
</div>
<div class="col-sm-6">
<label asp-for="Input.LastName" class="form-label"></label>
<input asp-for="Input.LastName" class="form-control" autocomplete="last-name">
<span asp-validation-for="Input.LastName" class="invalid-feedback" style="display:block"></span>
</div>
and the following model:
[Required]
[Display(Name = "First name")]
public string FirstName { get; set; }
[Required]
[Display(Name = "Last Name")]
public string LastName { get; set; }
Unfortunalely, when I send the form with empty values, despite of the error messages, inputs are still green:
I can add required
tag to the form, but I would like control it by the jQuery validation, because I am going to add more advanced validations in the future.
Any ideas how to make the field like the following when the data does not met validation requirements?
<input asp-for="Input.FirstName" class="form-control" autocomplete="first-name" required>>