When the title is not set the word field is duplicated

Created on 24 March 2023, almost 2 years ago

Problem/Motivation

When the title is not set the word field is duplicated on the CvValidatorBase

  protected function getElementTitle(array $element, $default = '') {

    $title = $this->getAttributeValue($element, 'title');

    if (empty($title) && empty($default)) {
      return $this->t('This field');
    }

    return $title ? $title : $default;
  }

Required validator

    // Drupal already adds the required attribute, so we don't need to set the
    // required rule.
    if ($is_required || $is_conditionally_required) {
      $message = $element['#required_error'] ??
        $this->t('@title field is required.', [
          '@title' => $this->getElementTitle($element),
        ]);

      return [
        'messages' => [
          'required' => $message,
        ],
      ];
    }

Steps to reproduce

  • Install clientside_validation
  • Create a field without a title attribute.
  • Submit the form without the field filled

The result will be something like:

Proposed resolution

Change "This field", to "This", I am not sure if there is a better text for it.

🐛 Bug report
Status

Needs review

Version

4.0

Component

Form Validation

Created by

🇪🇸Spain eduardo morales alberti Spain, 🇪🇺

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

Comments & Activities

Production build 0.71.5 2024