1

I am setting another webform on Drupal 8. I want to enable some fields based on the day of the week selected. I used JS on a site with Drupal 7, it is working fine, thanks to JSDrupal.

I would like to implement it on the Drupal 8 site with a regexp. I am using the HTML5 date field, not the Jquery datepicker. My concern is the same than before :

if the Day selected on field DATE_D( a Date field) is Tuesday OR Thursday then hide SELECT( select field).

Thank you

0

The Webform module for Drupal 8 supports patterns in the #states API (aka Conditional logic).

Example of pattern in conditional logic

3
  • Thanks for the tip. Sorry for the delay, had a busy day with students. But i am not using a select, i am using the HTML5 datepicker ( not jquery). It is not working with it or do i need to do additional things ? May 7 '18 at 22:10
  • You would have to write custom JS and PHP and calculate the day of the week and then conditionally hide/show the element
    – jrockowitz
    May 7 '18 at 22:29
  • Thank you. So bottom line is, I have to use a select or write custom js and PHP. Thank for your help May 7 '18 at 22:31
0

I doubt that you can achieve this without some JS involved.

You can use JS RegExp.

You could try Form API #states and try to hide the desired select field if some other field's value matches your conditions.

$form['my_select_element'] = [
  '#type' => 'select',
  '#states' => [
    // Hide this field when the 'weekday' radio has 'tuesday' or 'thursday' selected.
    'invisible' => [
      ':input[name="field_weekday[und]"]' => ['value' => 'tuesday'],
      'or',
      ':input[name="field_weekday[und]"]' => ['value' => 'thursday'],
    ],
  ],
];

(#states with multiple conditions, Source.)

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.