1

I am using a postcode lookup to fill in some forms fields when they type in a certain field. Now if the form has been submitted and the autocompleted fields are empty, they are marked as errored. If I then use the auto complete to fill them in, the error messages don't disappear as the field has not been focused or blurred.

Is there a way to force re-validation of the fields?

I have tried the following but nothing happens (the console is logged):

pca.on("load", (type, id, control) => {
  control.listen("populate", address => {
    console.log('populate'); // this gets hit

    $('.pca-form').validate(); // this does nothing
  });
});

I am using the unobtrusive version of validate if that makes a difference

Pete
  • 57,112
  • 28
  • 117
  • 166
  • Read the documentation, the SO wiki page, and search the [tag:jquery-validate] tag. The `.validate()` method is for initializing the plugin on your form. Since the Unobtrusive plugin is already constructing and calling `.validate()` for you, your call would always be ignored, despite the fact that it's not the trigger anyway. – Sparky Jan 06 '18 at 16:17

1 Answers1

2

As it turns out you call .valid() instead of .validate():

$('.pca-form').valid(); // this re-validates all fields
Pete
  • 57,112
  • 28
  • 117
  • 166