I have a wizard style webform with ajax enabled to load each wizard page. I'm using clientside validation with the jquery validation plugin. In the clientside validation jquery settings, I have enabled the option "Validate all forms before AJAX submit".

On the first page of the webform, clientside validation works fine and generates an inline error message after the invalid input with the correct markup:

<div class="form-item--error-message">
  <strong id="question_1-error" class="error">You must choose an answer.</strong>
</div>

But on the second page of the webform (loaded in via ajax), the clientside validation partially breaks. It still generates an inline error message - but the markup seems to revert to the default for the jquery validation plugin which is to wrap the error message in a label:

<label id="question_2-error" class="error" for="question_2">You must choose an answer.</label>

I think this may be caused by these lines in cv.jquery.validate.js towards the end of that file:

$(context).find('form').each(function() {
  $(this).validate(drupalSettings.cvJqueryValidateOptions);
});

On the first page of the wizard webform, context is the entire document object. But when the second page of the webform is loaded in via ajax, context becomes the form itself and the lines above do not run.

To fix I modified the above lines so that it always looks for forms within the document object:

$(document).find('form').each(function() {
  $(this).validate(drupalSettings.cvJqueryValidateOptions);
});

This solved the issue for me. Patch attached.

Comments

Glugmeister created an issue. See original summary.

abaier’s picture

I can confirm this behaviour on webform wizard pages using ajax. After applying the patch, CSV worked also on pages after the first one.

johan.gant’s picture

Version: 8.x-1.x-dev » 3.0.x-dev

I can confirm this issue still applies on version 3.0.x. The original patch needs a re-roll, will do that + upload shortly.

johan.gant’s picture

StatusFileSize
new547 bytes

Patch re-rolled against 3.0.x-dev, and attached.

hchonov’s picture