1

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 swith 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 ? The states work in normal field, but in the widget it do not works. This is my code. Please look the Gif #1 (working) and the Gif #2 (not working).

A created a hook_form_FORM_ID_alter() :

$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],
    ]
  ];

The #states is working here: The #states is working here

The #states is not working with the widget inline_entity_form_complex : The #states is not working with the widget inline_entity_form_complex

Jasmin
  • 103
  • 5

1 Answers1

1

I finally found the solution ! In modules/contrib/inline_entity_form/inline_entity_form.api.php there is several hooks. I used hook_inline_entity_form_entity_form_alter. I adapted the field name with the name updated by the widget, and works normally !

enter image description here

Jasmin
  • 103
  • 5