Ajax enabled Webform ignores client side form validation

Created on 30 January 2023, almost 2 years ago
Updated 27 June 2024, 5 months ago

Problem/Motivation

I have a contact webform, wich opens in side a modal and submits via ajax. I'm using for this the core ajax functionality introduced in https://www.drupal.org/project/webform/issues/2757491 β†’ . (I also tried to find a solution via SO, but it went pretty sideways: https://drupal.stackexchange.com/questions/314525/webform-ajax-how-to-al...)

I'm including the webform like this:

<div class="modal fade" id="contactModal" tabindex="-1" aria-labelledby="contactModalLabel" aria-hidden="true">
  <div class="modal-dialog modal-dialog-centered">
    <div class="modal-content">
      <div class="modal-header">
        <button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Schließen"></button>
      </div>
      <div class="modal-body pt-1">
        {{ { '#type': 'webform', '#webform': 'contact' } }}
      </div>
    </div>
  </div>
</div>

The webform has this config:

// ...
settings:
  ajax: true
  ajax_scroll_top: form
  ajax_progress_type: fullscreen
  ajax_effect: fade
  ajax_speed: null
// ...

Issue: If I submit it in the overlay, it loads via ajax, but the required fields are not validated clientside. I'm able to submit the form with empty fields, which leads then to a pretty massive error response and a generally unnessesary clumsy user experience.

Steps to reproduce

Create a webform with ajax enabled and some required field

Include the form in some template

Submit the form without filling any field - it submits and returns a lot of unnessessary error messages

Proposed resolution

Use at least the html5 client side validation, better the full webform client side validation js. Looking at the code, this should probably happen either in the ajax.options.beforeSubmit or ajax.options.beforeSerialize functions of the ajax api - see web/core/misc/ajax.js

Remaining tasks

User interface changes

API changes

Data model changes

πŸ› Bug report
Status

Active

Version

6.2

Component

Code

Created by

πŸ‡©πŸ‡ͺGermany Schoenef Unna

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Production build 0.71.5 2024