How to use #states with a container element? I come from read this Using the Drupal 7 Form API states system to create conditions between form elements and I'm able to use the #states with an input element like the title (textfield element), the problem is that if I try to use a container element the #states doesn't works.

This code works:

$form['field_courriels_des_autres']['#states']['disabled']['input[name="title"]']['filled'] = TRUE;


This code doesn' works:

$form['field_preciser']['#states']['enabled']['select[name="field_salle"]']['value'] = 'other';


I think that the problem is that the field_salle is a container.
As it's been mentioned, the #states property doesn't work for fieldsets, containers.
You need some JS here, e.g:

The form

$form['promo_code_trigger'] = [
  '#type' =&gt; 'container',
  '#attributes' =&gt; ['id' =&gt; ['promo-code-add-el']],
  'data' =&gt; [
    '#markup' =&gt; t('Add promotional code'),
  ]
];

$form['promo_code_wrapper'] = [
  '#type' =&gt; 'container',
  '#attributes' =&gt; [
    'id' =&gt; ['promo-code-add-el-triggered'],
    'class' =&gt; ['hidden'],
  ],
];


JS

$("#promo-code-add-el").on("click", function (e) {
  $('#' + e.target.id + "-triggered").toggleClass('hidden');
  $('#' + e.target.id).toggleClass('active');
});