How to programmatically require a field using Inline Entity Form I have a node form using an inline entity form widget for either selecting or creating taxonomy terms to be referenced from the node.  The field should be required at a certain moderation state, but in the early stages of moderation the field does not need to be required.  I'm trying to make this change in hook_form_alter
I tried comparing the values of $form in the alter function when the field had been set to required, and when it hadn't.  The only differences were within $form['field_name']['widget']:
$form['field_name']['widget']['#required'] =&gt; 0
vs.
$form['field_name']['widget']['#required'] =&gt; 1
and
$form['field_name']['widget'][#element_validate] =&gt; Array
                (
                    [0] =&gt; Array
                        (
                            [0] =&gt; Drupal\inline_entity_form\Plugin\Field\FieldWidget\InlineEntityFormComplex
                            [1] =&gt; updateRowWeights
                        )

                )

vs.
$form['field_name']['widget'][#element_validate] =&gt; Array
                (
                    [0] =&gt; Array
                        (
                            [0] =&gt; Drupal\inline_entity_form\Plugin\Field\FieldWidget\InlineEntityFormComplex
                            [1] =&gt; updateRowWeights
                        )

                    [1] =&gt; Array
                        (
                            [0] =&gt; Drupal\inline_entity_form\Plugin\Field\FieldWidget\InlineEntityFormComplex
                            [1] =&gt; requiredField
                        )

                )


Just adding $form[&quot;field_name&quot;][&quot;widget&quot;][&quot;#required&quot;] = TRUE; to the alter didn't change anything, and trying to add the #element_validate bit lead to an error:

User error: &quot;0&quot; is an invalid render array key in Drupal\Core\Render\Element::children() (line 97 of core/lib/Drupal/Core/Render/Element.php).

How can I programmatically require an inline entity form field in a hook form alter?
I'm not sure if this will work out of the box for you, but I wrote this module https://www.drupal.org/project/require_on_publish to solve a similar problem. You might be able to borrow some of the ideas in there around adding constraints to custom fields to achieve your desired functionality.