FormSetFieldError Action does not work for DropDown fields
>>> [!note] Migrated issue
<!-- Drupal.org comment -->
<!-- Migrated from issue #3326056. -->
Reported by: [danielspeicher](https://www.drupal.org/user/3621778)
Related to !278
>>>
<h3 id="summary-problem-motivation">Problem/Motivation</h3>
<p>I tagged this as a bug, even there is a workaround described below.</p>
<p>If the field is a drop-down, the error message does not appear.</p>
<h4 id="summary-steps-reproduce">Steps to reproduce</h4>
<p>Just create a content type with a DropDrownList<br>
Add an ECA model like the one attached.<br>
Now try to create a content of this type.</p>
<p>I figured out:</p>
<p>For a required field, for example, Drupal Core passes the correct field name to <code>setErrorByName</code> in <code>FormState.php</code>.</p>
<p>Our Action Base class <code>FormFieldValidateActionBase</code> returns the wrapper <code>field_grp_subitem_retirement_wrapper</code> of that field here:</p>
<pre>if ($target_element = &$this->getTargetElement()) {<br> if (isset($target_element['#parents'])) {<br> $form_state->setErrorByName(implode('][', $target_element['#parents']), $message);<br> return;<br> }<br> }</pre><p>For example, if the field name (DropDown field) is <code>foo</code>, this code passes <code>foo_wrapper</code> to the <code>setErrorByName</code> method.</p>
<p>Note: In my model, a changed the field name to <code>foo_wrapper</code>, then the code returns the correct field name, and it works. But I think, we must fix this, because it is not obvious for a user to add the word <code>wrapper</code>.</p>
<p>@mxh Maybe you have a good idea to fix this.</p>
issue