Form state api not working on adding new paragraph

Created on 19 April 2022, over 3 years ago
Updated 5 August 2025, about 2 months ago

I have programmatically added #state into fields in a paragraph works fine for existing fields in a form. But on clicking ad more button on paragraph to add more fields the hidden fields show up. i tries this Patch but it didnt work for me.

I have used this hook to alter the field to ass #state.

function mymodule_field_widget_entity_reference_paragraphs_form_alter(&$element, &$form_state, $context) {
$element['subform']['field_title']['#states'] = [
       'invisible' => [
            '#edit-parent-field-0-subform-parent-field-content-'.$element['#delta'].'-subform-target-field-wrapper select' => ['value' => 'value']
          ]  
        ];
}
🐛 Bug report
Status

Closed: works as designed

Version

1.12

Component

Code

Created by

🇮🇳India arpitk Indore

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.

  • 🇺🇸United States vetchneons

    I am trying to use a node field value to control the visibility of a paragraph form field.

    This works on initial node form load, but the #state does not persist when the "add more" paragraph form is submitted.

    I believe this is happening with the paragraph subform rebuild.

    The #state does apply again if I change the field that controls the paragraphs field visibility after the new paragraph forms have rendered.

Production build 0.71.5 2024