Error when we have custom form with ajax

Created on 19 February 2024, 9 months ago

Problem/Motivation

the problem when we have a form with a field address, we use the form hook and we need to ajax another set of fields in the same form, but we only want to modify the subform, not all forms with an address of field. then the field widget always sends the field address to the validation form, the ajax form definitely doesn't check the validation on the address it will call errorElement. The element in this case is null

Proposed resolution

This patch will avoid this error. it should check the value before use, avoid undefined key in variable

πŸ› Bug report
Status

Active

Version

2.0

Component

Code

Created by

πŸ‡«πŸ‡·France lazzyvn paris

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

Comments & Activities

  • Issue created by @lazzyvn
  • πŸ‡«πŸ‡·France lazzyvn paris
  • Status changed to Needs review 9 months ago
  • πŸ‡·πŸ‡ΈSerbia bojanz

    @lazzyvn
    We need either a test or a small form class where the problem can be observed.

    Changing status to "needs review" to signal that there is a patch here.

  • πŸ‡«πŸ‡·France lazzyvn paris

    I tested twice on 2 machines and it drives me crazy. Same version, same project but one has an error, the other does not. it never calls the formError.
    Environment has an error Drupal 10.2.3, PHP 8.2

  • πŸ‡ΊπŸ‡ΈUnited States goose2000

    I am getting this error too, triggered when "Add another item" is clicked in a add form:

    TypeError: Drupal\address\Plugin\Field\FieldWidget\AddressDefaultWidget::errorElement(): Argument #1 ($element) must be of type array, null given, called in D:\wwwroot\pss-2024-fix\web\core\lib\Drupal\Core\Field\WidgetBase.php on line 580 in Drupal\address\Plugin\Field\FieldWidget\AddressDefaultWidget->errorElement() (line 188 of D:\wwwroot\pss-2024-fix\web\modules\contrib\address\src\Plugin\Field\FieldWidget\AddressDefaultWidget.php).

    Drupal 10.3.5
    PHP 8.1.29
    Version: 2.0.2

Production build 0.71.5 2024