I am working on a form_alter() based on Form API states which is about switching a field choice based on the value of a select field as below;

'select[name="field_date_type"]' => ['value' => 'allday']

I would like to know what syntax is required for changing the field widget from select to boolean or checkboxes or radios.

I have tried switching select to boolean, checkbox and radio but none are working for me.

What am I doing wrong?


Assuming you mean checkbox (HTML doesn't have a boolean input type), the property is checked, so you can use:

':input[name="field_date_type"]' => ['checked' => TRUE]
| improve this answer | |
  • Hmm. This isn't working for me. Obs missing something. pastebin.com/rH7xuMBq – MrPaulDriver Jun 28 '18 at 8:07
  • The only thing I can spot that might be wrong in that pastebin is that you're wrapping TRUE with quotes. Try it without, because other than that it looks like it should work. Core uses the same pattern in dozens of places, and it's even used as the example in the comments for drupal_process_states(): ':input[name="remote_checkbox"]' => array('checked' => TRUE). – Clive Jun 29 '18 at 19:39

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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