1

Recently I have encountered the strange behavior of setting form created with Form API in Drupal 8.

I am using #states to hide one of the form elements ( radios ) when another element is empty. The problem is - it doesn't work with Aggregate JavaScript files option. After you submit the form, this element is still visible - even if condition to hide it is fulfilled.

When I disable Aggregate JavaScript files option, it works as expected - radios are hidden.

Is there anything I can do to solve this problem?

4
  • Have you tried on a fresh site? It's definitely not a core bug or none of the admin forms would work properly when aggregation was turned on (and they do). What other modules do you have installed that could mess with forms or JS?
    – Clive
    Commented Jul 26, 2017 at 16:04
  • Currently my module is only one that is 'extra'. Commented Jul 26, 2017 at 16:16
  • And when you disable your own module is the problem still there? With forms other than your own I mean?
    – Clive
    Commented Jul 26, 2017 at 16:19
  • I have checked only my module but never noticed similar behavior in the different module ( when I was skimming thru other options ). The thing is I'm not using Drupal on a daily basis, so I could easily miss this. ;) My code looks like this: $form['login'] = [ '#type' => 'textfield', '#title' => t('Your login:'), '#default_value' => $config->get('login'), '#states' => array( 'visible' => array( ':input[name="settings"]' => array('value' => '1') ), ) ]; Is there anything more to make states work? Commented Jul 26, 2017 at 16:32

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.