Score:1

How to hide a form element when a datetime widget is filled using #states

sa flag

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?

Kevin avatar
in flag
Have you tried `['!value' => '']` or `['!value' => '(placeholder value)']`? Also https://stackoverflow.com/a/25295617/295112
Baud avatar
sa flag
Many thanks, it is working with `['value' => '']` (in my above code). If you add the answer, I can grant you the bounty!!!
Score:1
in flag

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

['!value' => '']

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.