1

The following code is working well to hide a button when a textfield is filled, but it is not working when a datetime widget is encoded:

$form['my_button'] = [
  '#type' => 'container',
  'submit' => [
    '#type' => 'submit',
    '#value' => t("Click on me"),
    '#submit' => ['submit_me']),
    '#states' => [
      'visible' => [
        ':input[data-drupal-selector=selector-of-my-text-field]' => [ 
          'filled' => FALSE,
        ],
      ],
    ],
  ],
];

Any hint?

2
  • 1
    Have you tried ['!value' => ''] or ['!value' => '(placeholder value)']? Also stackoverflow.com/a/25295617/295112
    – Kevin
    Jul 15, 2021 at 12:55
  • Many thanks, it is working with ['value' => ''] (in my above code). If you add the answer, I can grant you the bounty!!!
    – Baud
    Jul 16, 2021 at 8:46

1 Answer 1

1
+50

"filled" won't work for date elements, but you can check if it is not empty with:

['!value' => '']

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.