Conditional field in inline_entity_form (#states) doesn't work

Created on 7 January 2022, almost 3 years ago
Updated 2 March 2024, 9 months ago

Problem/Motivation

Hello, I can't implement states in a inline entity form complex widget form.

Steps to reproduce

Create a parent and a child entity.
In the child entity, create a text field A and B, and a checkbox C.
In the parent entity create a field D, that allows to refer the child entity with inline_entity_form_complexe widget.

Create a #state in the child entity with the hook hook_form_FORM_ID_alter() that allow to hide/show A or B a field when the checkbox C is checked/unchecked.

My case

I have entity "parking_lot" with several "pricings", in the "parking_lot" entity form, there is a field "pricings" using the widget inline_entity_form_complex. In the parking_lot form I set conditional fields with the #states API (to display fields only sometimes with a boolean field). The #states works but only in the original form of a "pricing" entity, but when I edit a pricing from the parking_lot entity, the #states doesn't works. How to set #states in a inline_entity_form_complex field widget ? Is it a issue ? The states work in normal field, but in the widget it do not works. Please look the Gif #1 (working) and the Gif #2 (not working).

This is my code :

$form['field_level_time_unit']['#states'] = [
    'invisible' => [
      'input[name="field_level_pricing_mode"]' => ['value' => 0],
    ]
  ];

  $form['field_level_price']['#states'] = [
    'invisible' => [
      'input[name="field_level_pricing_mode"]' => ['value' => 0],
    ]
  ];

  $form['field_level_of_reference']['#states'] = [
    'visible' => [
      'input[name="field_level_pricing_mode"]' => ['value' => 0],
    ]
  ];

✨ Feature request
Status

Closed: duplicate

Version

1.0

Component

Code

Created by

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 dcam

    An example solution was given in comment #10, so I'm closing this. If anyone needs additional help, then feel free to reopen this issue.

  • Status changed to Closed: duplicate 9 months ago
  • πŸ‡«πŸ‡·France dqd London | N.Y.C | Paris | Hamburg | Berlin

    IEF support wasn't ready yet and needed a complete FR work on this to work properly. So this is not "Closed (works as designed)". As @Murz already stated in #8 there is a work in progress on ✨ Support for Inline Entity Form Fixed which will be committed so I close this as duplicate and suggest users to go into the other issue to track the changes made for IEF support.

Production build 0.71.5 2024