Webform EmailConfirm - clientside validation - not working when EmailConfirm is inside a webform container element/section element or visibility controlled via a condition field

Created on 9 February 2023, almost 2 years ago

Below has been tested with D9.4.9, webform 6.1.3 and clientside_validation 4.0.1

Problem/Motivation

- Webform Email Confirm field outside any webform container or section element
-- Checks Empty Input for Email and Confirm email fields
-- Doesn't compare the inputs for Email and Confirm Email. Shows error after Submit

- Webform Email Confirm inside a webform container element/section element or visibility controlled via a condition
-- Doesn't check Empty Input for Email and Confirm email fields
-- Doesn't compare the inputs for Email and Confirm Email. Shows error after Submit

Proposed resolution

Snippet below in \contrib\webform\modules\webform_clientside_validation\webform_clientside_validation.module needs reviewing

/**
 * Process 'webform_email_confirm' element and add 'equal_to' validation rules.
 *
 * @see \Drupal\webform\Element\WebformEmailConfirm::processWebformEmailConfirm
 */
function _webform_clientside_validation_webform_email_confirm_process(&$element, FormStateInterface $form_state, &$complete_form) {
  $validation_properties = [
    '#equal_to' => $element['#name'] . '[mail_1]',
    '#equal_to_error' => t('The specified email addresses do not match.'),
  ];
  if (empty($element['#flexbox'])) {
    $element['mail_2'] += $validation_properties;
  }
  else {
    $element['flexbox']['mail_2'] += $validation_properties;
  }
  return $element;
}
🐛 Bug report
Status

Needs work

Version

6.1

Component

Code

Created by

🇬🇧United Kingdom mashraf Berkshire

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

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

  • Status changed to Active almost 2 years ago
  • 🇮🇹Italy apaderno Brescia, 🇮🇹
  • Status changed to Postponed: needs info almost 2 years ago
  • 🇺🇸United States jrockowitz Brooklyn, NY

    Please post an example webform which can be used to reproduce this issue.

  • 🇬🇧United Kingdom mashraf Berkshire
  • Status changed to Active almost 2 years ago
  • 🇬🇧United Kingdom mashraf Berkshire
  • 🇺🇸United States jrockowitz Brooklyn, NY

    The attached webform replicates this issue. I am not sure what is the root cause.

    I am moving this to webform 6.2.x

  • 🇬🇧United Kingdom mashraf Berkshire

    Managed to get it to work by adding required class to the element which is inside the container.

    Full webform source:

    name:
      '#type': name
      '#title': Name
      '#title__required': true
      '#first__required': true
      '#middle__access': false
      '#last__required': true
      '#suffix__access': false
      '#degree__access': false
    address:
      '#type': address
      '#title': Address
      '#address__required': true
      '#city__required': true
      '#state_province__access': false
    confirm_email_outside_container_:
      '#type': email_confirm
      '#title': 'Confirm Email (Outside Container)'
      '#required': true
      '#required_error': 'Confirm Email (Outside Container) is required'
      '#confirm__title': 'Confirm Email (Outside Container)'
    what_language_badge_would_you_like_:
      '#type': radios
      '#title': 'What language badge would you like?'
      '#options':
        English: English
        Cymraeg: Cymraeg
      '#required': true
      '#required_error': 'This is a required field'
    container:
      '#type': container
      '#states':
        visible:
          ':input[name="what_language_badge_would_you_like_"]':
            value: Cymraeg
      email:
        '#type': email_confirm
        '#title': 'Email (inside container)'
        '#required': true
        '#required_error': 'Email address is required'
        '#attributes':
          class:
            - required
        '#confirm__title': 'Confirm your email (inside container)'

    I will review the fix and see best options to add this to the module.

  • Status changed to Closed: outdated 25 days ago
  • 🇺🇸United States jrockowitz Brooklyn, NY

    Marking outdated due to lack of progress. This feels like an edge case issue

Production build 0.71.5 2024