I've tried searching the issue queue for this, so apologies if this is a duplicate.

We have an issue on a site where we have a multistep webform, with required fields on each step. The user can navigate backwards to a previous step if they so wish.

The problem is that if a user fills clicks the back button without filling out all the required fields on the current step, then they get a "X field is required" type messages. We'd like to be able to not trigger the validation checks if the back button is pressed, but still retain those checks if the user clicks Next.

Is there any way to disable the validation checks on the back button?

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

stella created an issue. See original summary.

jrockowitz’s picture

Status: Active » Needs review
FileSize
539 bytes

The is very old issue that I was almost certain was fixed. I really need to get JavaScript testing setup.

  • jrockowitz committed 81ded16 on 8.x-5.x
    Issue #2854871 by jrockowitz: Back/previous button triggers form...
jrockowitz’s picture

Status: Needs review » Fixed

I committed the patch. Please download and review the latest dev release.

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.

Courtenay’s picture

Hi,

I still have this same issue using version Webform 8.x-5.x - i can see in the webform.form.js file that the "patch" is in there...

Thanks

scoff’s picture

I still have this using 8.x-5.0-beta15

To reproduce make any field on step 2 of the "Example: Wizard" form required and then try step one - step two - back to step one.

scoff’s picture

8.x-5.0-beta16, same as above

I think HTML5 novalidate works fine and there's no client-side validation if I click Back, but after the form is submitted there's still server side validation which displays a message and prevents me from actually going back until I fill out the required field.

Looks like a major issue to me.

duncan.moo’s picture

Per this issue I simply added the following:

-- do not use this solution, see below --

<?php
function MYMODULE_webform_submission_form_alter(&$form, FormStateInterface $form_state, $form_id) {
  if ($form_id === 'FORM_ID') {
    // Disable validation on back button
    if (!empty($form['actions']['wizard_prev'])) {
      $form['actions']['wizard_prev']['#limit_validation_errors'] = [];
    }
  }
}
?>

-- do not use this solution, see below --

jrockowitz’s picture

Status: Closed (fixed) » Needs work

I think this needs to be added the wizard and preview previous buttons.

@see http://cgit.drupalcode.org/webform/tree/src/WebformSubmissionForm.php#n844

jrockowitz’s picture

Status: Needs work » Needs review
FileSize
1.11 KB

Status: Needs review » Needs work

The last submitted patch, 11: back_previous_button-2854871-11.patch, failed testing. View results
- codesniffer_fixes.patch Interdiff of automated coding standards fixes only.

  • e6c1fa2 committed on 8.x-5.x
    Issue #2854871 by jrockowitz: Back/previous button triggers form...
jrockowitz’s picture

Status: Needs work » Postponed (maintainer needs more info)
FileSize
3.61 KB

Once, I started to look into the issue, I realized that using #limit_validation_errors causes major issues on complex wizard forms.

I added some notes explaining why the webform module is not using '#limit_validation_errors'.
@see http://cgit.drupalcode.org/webform/commit/?id=e6c1fa2

I can't reproduce the issue described in #7. Attached is the webform I am using the replicate the steps in #7.

jrockowitz’s picture

Status: Postponed (maintainer needs more info) » Closed (cannot reproduce)