0

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?

1 Answer 1

2

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]
2
  • Hmm. This isn't working for me. Obs missing something. pastebin.com/rH7xuMBq Commented Jun 28, 2018 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
    Commented Jun 29, 2018 at 19:39

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.