My form has an autofill button
that populates some inputs
with default information. However, populating the fields does not clear away any validation messages that were already present, unless the user manually clicks over or tabs through the elements. The form will still submit even though the messages are present. Here is the JavaScript that does the populating.
$('#autofillButton').click(function () {
$('#address').val("localhost");
$('#port').val("12345");
$('#receiveTimeout').val("5000");
$('#sendtimeout').val("5000");
})
Someone suggested adding $("form").validate().resetForm();
to my click function, but that did not work for me. The validation messages remained. Here is a relevant slice of my View.
<p>
@Html.LabelFor(c => c.address):
@Html.TextBoxFor(c => c.address)
@Html.ValidationMessageFor(c => c.address, String.Empty, new { @class ="errorMessage"})
</p>
<p>
@Html.LabelFor(c => c.port):
@Html.TextBoxFor(c => c.port)
@Html.ValidationMessageFor(c => c.port, String.Empty, new { @class ="errorMessage"})
</p>
How can I reset only the validation messages without resetting the entire form?