I can use conditional logic with single value entity reference select. For example selecting taxonomy term "something else" can make a text field "what else" visible.

I have not however been able to use conditional logic with an entity reference select element with multiple values. I can do this with entity checkboxes but not with list of entities that is so long checkboxes are out of the question. Is this possible at all?

Comments

simohell created an issue. See original summary.

jrockowitz’s picture

Status: Active » Postponed (maintainer needs more info)

Please export and upload an example of the problem.

simohell’s picture

Here is an example. Is the YAML enough?
Single select, radio buttons and checkboxes work.
Multiple select with these settings appears initially but is hidden when any value is chosen and remains hidden when no value is chosen again. Is there a syntax that would work for multiple select?

single_select:
  '#type': fieldset
  '#title': 'Single select'
  '#title_display': before
  select_one:
    '#type': entity_select
    '#title': 'Select one'
    '#target_type': taxonomy_term
    '#selection_handler': 'default:taxonomy_term'
    '#selection_settings':
      target_bundles:
        testing: testing
  show_me:
    '#type': markup
    '#states':
      visible:
        ':input[name="select_one"]':
          value: '34'
    '#markup': '<h2>Here I am!</h2>'
radio_buttons:
  '#type': fieldset
  '#title': 'Radio buttons'
  '#title_display': before
  check_one:
    '#type': entity_radios
    '#title': 'Check one'
    '#target_type': taxonomy_term
    '#selection_handler': 'default:taxonomy_term'
    '#selection_settings':
      target_bundles:
        testing: testing
  show_me2:
    '#type': markup
    '#states':
      visible:
        ':input[name="check_one"]':
          value: '34'
    '#markup': '<h2>Here I am!</h2>'
checkboxes:
  '#type': fieldset
  '#title': Checkboxes
  '#title_display': before
  check_multiple:
    '#type': entity_checkboxes
    '#title': 'Check multiple'
    '#target_type': taxonomy_term
    '#selection_handler': 'default:taxonomy_term'
    '#selection_settings':
      target_bundles:
        testing: testing
  show_me3:
    '#type': markup
    '#states':
      visible:
        ':input[name="check_multiple[34]"]':
          checked: true
    '#markup': '<h2>Here I am!</h2>'
multiple_select:
  '#type': fieldset
  '#title': 'Multiple select'
  '#title_display': before
  select_multiple:
    '#type': entity_select
    '#title': 'Select multiple'
    '#multiple': true
    '#target_type': taxonomy_term
    '#selection_handler': 'default:taxonomy_term'
    '#selection_settings':
      target_bundles:
        testing: testing
  show_me4:
    '#type': markup
    '#states':
      visible:
        ':input[name="select_multiple[]"]':
          value: '34'
    '#markup': '<h2>Here I am!</h2>'
jrockowitz’s picture

Status: Postponed (maintainer needs more info) » Postponed

There is a core issue #1149078: States API doesn't work with multiple select fields and the Webform UI does not support this functionality.

We are blocked until this functionality is fixed in Drupal core.

jrwest_webguy’s picture

I think I might be running into this old issue. Can anyone confirm that this is still a problem for Webforms?

I have a multi-page form. On page two I have conditional logic applied to a 'Fieldset'. The elements within the 'Fieldset' include one 'Select' element, a 'Markup/HTML' element, a 'Radio' button with 2 possible values, and a 'Textfield'. The Select element and Textfield have additional Conditional logic applied to them, even though they exist within the 'Fieldset'. I've tried to move them outside of the Fieldset; however -- I think because I'm still within the 'Page' element' -- I'm still getting an error. The error is (paraphrasing), "An illegal choice has been made. Contact an Admin."

I'm currently running 8.x-5.2, which I really like because now I can email file attachments! :) But, the logic on this one form which is kinda important is now the bane of my existence.

jrockowitz’s picture

@jwest1@eastern.edu I am not sure your issue is related

If possible you should create an isolated example that can be used to replicate your specific issue?

jrwest_webguy’s picture

@jrockowitz I’m not sure what you’re suggesting I do. Please clarify.

jrockowitz’s picture

Create a simple webform that replicates the problem described in #5, export it, and attach it here.

jrwest_webguy’s picture

This is not a simple webform. It is a very complex webform built using your heretofore excellent Webform module for Drupal 8. As far as I know, we were not having any problems with it until we updated to Webforms 8.x-5.2, I believe I was at 8.x-5.0 before. Here is an example of the code I'm trying to use:

start:
  '#type': wizard_page
  '#title': Start
  pi_page_markup:
    '#type': markup
    '#display_on': both
    '#markup': "<strong>This is how to reproduce the &#39;Illegal Choice&#39; error with Webforms 8.x-5.2.&nbsp; Here are some random fields to fill out.&nbsp; The problem starts on page 2.&nbsp; I&#39;ve tried this form on D8.6 and D8.7, using PHP7.0 and PHP7.2, all combos show error on page 2.</strong>\r\n<p>This form worked fine before upgrading to Webforms 8.x-5.2, I believe I was at 8.x-5.0 before.&nbsp; Also, &#39;the error&#39; does not show up if you run a &#39;Test&#39; on the form, it only shows up when you &#39;Manually&#39; fill out the form.<br />\r\n<br />\r\nThere is conditional logic on this page (Page 1) related to whether the TextArea for address is Editable, or if it is disabled and contains a message that the address is not different than Home Address, based on the answer to the &#39;Will you be living at your Address next year&#39;.</p>"
  last_name:
    '#type': textfield
    '#title': 'Last Name:'
    '#required': true
  first_name:
    '#type': textfield
    '#title': 'First Name:'
    '#required': true
  date_of_birth:
    '#type': date
    '#title': 'Date of Birth:'
    '#required': true
    '#date_date_max': today
  permanent_home_address:
    '#type': address
    '#title': 'Home Address'
    '#title_display': before
    '#address__title': 'Street:'
    '#address__required': true
    '#address_2__title': 'Address 2:'
    '#city__title': 'City/Town:'
    '#city__required': true
    '#state_province__title': 'State/Province:'
    '#state_province__required': true
    '#postal_code__title': 'Zip/Postal Code:'
    '#postal_code__required': true
    '#country__access': false
  will_you_be_living_at_your_address_next_year_:
    '#type': radios
    '#title': 'Will you be living at your Address next year?'
    '#options': yes_no
    '#required': true
  anticipated_address_info_y:
    '#type': textarea
    '#title': 'Anticipated Address Info:'
    '#required': true
    '#states':
      visible:
        ':input[name="will_you_be_living_at_your_address_next_year_"]':
          value: 'Yes'
      disabled:
        ':input[name="will_you_be_living_at_your_address_next_year_"]':
          value: 'Yes'
    '#default_value': 'Same as Permanent Home Address'
  anticipated_address_info_n:
    '#type': textarea
    '#title': 'Anticipated Address Info:'
    '#required': true
    '#states':
      visible:
        ':input[name="will_you_be_living_at_your_address_next_year_"]':
          value: 'No'
  home_phone:
    '#type': tel
    '#description': 'Your phone number must conform to the format of the example.'
    '#description_display': tooltip
    '#maxlength': '14'
    '#placeholder': 'Ex. (555) 555-5555'
    '#title': 'Home Phone:'
applicant_status:
  '#type': wizard_page
  '#title': 'Drupal Status'
  drupal_8_is_:
    '#type': radios
    '#title': 'Drupal 8 is:'
    '#options':
      'A good CMS': 'A good CMS'
      'A bad CMS': 'A bad CMS'
      'What''s a Drupal?': 'What''s a Drupal?'
    '#required': true
  would_you_recommend_drupal_8_to_other_web_site_builders_:
    '#type': radios
    '#title': 'Would you recommend Drupal 8 to other web site builders?'
    '#options': yes_no
    '#required': true
    '#states':
      visible:
        ':input[name="drupal_8_is_"]':
          value: 'A good CMS'
  trad_yes_markup:
    '#type': processed_text
    '#states':
      visible:
        ':input[name="would_you_recommend_drupal_8_to_other_web_site_builders_"]':
          value: 'Yes'
    '#display_on': both
    '#text': "<p><strong>Good / Yes</strong> does not seem to be a problem, because it leads to exposure of other hidden elements, which MAY be the problem.&nbsp; (I am keenly suspicious of the 'Year' field, you will see shortly.)</p>\r\n"
    '#format': full_html
  trad_no_markup:
    '#type': processed_text
    '#states':
      visible:
        ':input[name="would_you_recommend_drupal_8_to_other_web_site_builders_"]':
          value: 'No'
    '#display_on': both
    '#text': "<p><strong>Good / No</strong> (you like Drupal but you would NOT recommend D8) does seem to be a problem, because it does not lead to exposure of hidden Year field, which I suspect might be the problem.</p>\r\n\r\n<p>I have also confirmed this TEST form does throw the error on my Drupal 8.6 / PHP 7.0 (Production) web server.&nbsp; I'm sure it will also throw the error on my Drupal 8.6 (or 8.7) / PHP 7.2 (Development) web server.</p>\r\n"
    '#format': full_html
  ntrad_markup:
    '#type': processed_text
    '#states':
      visible:
        ':input[name="drupal_8_is_"]':
          value: 'What''s a Drupal?'
    '#display_on': both
    '#text': "<p><strong>What's a Drupal? </strong>(and bad CMS) answered for 'Drupal 8 is:' both result in the user NOT being shown the 'Would you Recommend D8 . . .' question, which again leaves the 'Year' field hidden.</p>\r\n"
    '#format': full_html
  ug2grad:
    '#type': fieldset
    '#title': d8woke_track
    '#title_display': invisible
    '#states':
      visible:
        - ':input[name="would_you_recommend_drupal_8_to_other_web_site_builders_"]':
            value: 'Yes'
        - or
        - ':input[name="drupal_8_is_"]':
            value: 'A bad CMS'
    '#attributes':
      style: 'border: none;'
    what_versions_of_drupal_are_you_having_trouble_with_:
      '#type': select
      '#title': 'What versions of Drupal are you having trouble with?'
      '#options':
        6.x: 6.x
        7.x: 7.x
        8.x: 8.x
        9.x: 9.x
      '#required': true
      '#states_clear': false
    ug2grad_markup:
      '#type': markup
      '#display_on': both
      '#markup': 'These elements, including the Drupal version select element just above, only appear if you answer <strong>Good / Yes</strong> to the &#39;Drupal 8 is&#39; and &#39;Would recommend . . .&#39; questions, respectively, at the top of Page 2.'
    sfe_planned:
      '#type': radios
      '#title': 'How long have you been working with Drupal?'
      '#options':
        'Less than 5 years': 'Less than 5 years'
        'More than 5 years': 'More than 5 years'
      '#states':
        visible:
          ':input[name="drupal_8_is_"]':
            value: 'A good CMS'
      '#states_clear': false
      '#default_value': None
    start_year:
      '#type': textfield
      '#title': 'What year did you start working with Drupal?'
      '#description': 'Please enter a 4-digit year.'
      '#help': 'What year will you begin attendance?'
      '#title_display': inline
      '#description_display': after
      '#minlength': '4'
      '#maxlength': '4'
      '#required': true
      '#states':
        visible:
          ':input[name="drupal_8_is_"]':
            value: 'A good CMS'
          ':input[name="sfe_planned"]':
            checked: true
          ':input[name="would_you_recommend_drupal_8_to_other_web_site_builders_"]':
            '!value': 'No'
      '#attributes':
        style: 'width: 180px;'
  grad_track:
    '#type': fieldset
    '#title': wad_track
    '#title_display': invisible
    '#states':
      visible:
        ':input[name="drupal_8_is_"]':
          value: 'What''s a Drupal?'
    '#attributes':
      style: 'border: none;'
    the_rock_you_are_living_under_which_country_is_it_in_:
      '#type': textfield
      '#title': 'The rock you are living under, which country is it in?'
      '#required': true
  bs_markup:
    '#type': markup
    '#states':
      visible:
        - ':input[name="drupal_8_is_"]':
            value: 'A good CMS'
        - or
        - ':input[name="drupal_8_is_"]':
            value: 'A bad CMS'
    '#display_on': both
    '#markup': "<h1>Basic Skills</h1>\r\nThe following Flexbox layout elements are visible if you answer the Drupal 8 is: question with <strong>Good OR Bad</strong>.&nbsp; We need to do it this way so that they do NOT show when the &#39;Drupal 8 is:&#39; question is Unchecked.&nbsp; While the Flexbox layout elements, which all include a select field, have conditional logic applied; the elements within the Flexbox layout element do not have Conditional logic applied."
  basic_skills_matrix_r:
    '#type': flexbox
    '#states':
      visible:
        - ':input[name="drupal_8_is_"]':
            value: 'A good CMS'
        - or
        - ':input[name="drupal_8_is_"]':
            value: 'A bad CMS'
    '#attributes':
      style: 'margin: 0;'
    '#format': fieldset
    '#align': horiz
    discipline_r:
      '#type': textfield
      '#title': Discipline
      '#size': '10'
      '#autocomplete': 'off'
      '#disabled': true
      '#readonly': true
      '#required': true
      '#states_clear': false
      '#default_value': 'Editor Friendliness'
      '#attributes':
        style: 'margin: 0;'
    drupal_version_2:
      '#type': select
      '#title': 'Drupal Version You are Grading'
      '#options':
        6.x: 6.x
        7.x: 7.x
        8.x: 8.x
        9.x: 9.x
      '#required': true
      '#attributes':
        style: 'margin: 0;'
    date_taken_r:
      '#type': date
      '#title': 'Date You Started Working With Drupal'
      '#required': true
      '#attributes':
        style: 'margin: 0;'
      '#date_date_max': today
    score_received_r:
      '#type': number
      '#title': 'Your Score'
      '#maxlength': '3'
      '#required': true
      '#attributes':
        style: 'margin: 0;'
      '#min': '0'
      '#max': '999'
      '#step': '1'
  basic_skills_matrix_w:
    '#type': flexbox
    '#states':
      visible:
        - ':input[name="drupal_8_is_"]':
            value: 'A good CMS'
        - or
        - ':input[name="drupal_8_is_"]':
            value: 'A bad CMS'
    '#attributes':
      style: 'margin: 0;'
    '#format': fieldset
    '#align': horiz
    discipline_w:
      '#type': textfield
      '#title': Discipline
      '#title_display': invisible
      '#size': '10'
      '#autocomplete': 'off'
      '#disabled': true
      '#readonly': true
      '#required': true
      '#states_clear': false
      '#default_value': 'Administrator friendliness'
      '#attributes':
        style: 'margin: 0;'
    drupal_version_3:
      '#type': select
      '#title': 'Drupal Version You are Grading'
      '#title_display': invisible
      '#options':
        6.x: 6.x
        7.x: 7.x
        8.x: 8.x
        9.x: 9.x
      '#required': true
      '#attributes':
        style: 'margin: 0;'
    date_taken_w:
      '#type': date
      '#title': 'Date Taken'
      '#title_display': invisible
      '#required': true
      '#attributes':
        style: 'margin: 0;'
      '#date_date_max': today
    score_received_w:
      '#type': number
      '#title': 'Score Received'
      '#title_display': invisible
      '#maxlength': '3'
      '#attributes':
        style: 'margin: 0;'
      '#required': true
      '#min': '0'
      '#max': '999'
      '#step': '1'
  basic_skills_matrix_m:
    '#type': flexbox
    '#states':
      visible:
        - ':input[name="drupal_8_is_"]':
            value: 'A good CMS'
        - or
        - ':input[name="drupal_8_is_"]':
            value: 'A bad CMS'
    '#attributes':
      style: 'margin: 0;'
    '#format': fieldset
    '#align': horiz
    discipline_m:
      '#type': textfield
      '#title': Discipline
      '#title_display': invisible
      '#size': '10'
      '#autocomplete': 'off'
      '#disabled': true
      '#readonly': true
      '#required': true
      '#states_clear': false
      '#default_value': 'Visitor friendliness'
      '#attributes':
        style: 'margin: 0;'
    drupal_version_1:
      '#type': select
      '#title': 'Drupal Version You are Grading'
      '#title_display': invisible
      '#options':
        6.x: 6.x
        7.x: 7.x
        8.x: 8.x
        9.x: 9.x
      '#required': true
      '#attributes':
        style: 'margin: 0;'
    date_taken_m:
      '#type': date
      '#title': 'Date You Started Working With This Version of Drupal'
      '#title_display': invisible
      '#required': true
      '#attributes':
        style: 'margin: 0;'
      '#date_date_max': today
    score_received_m:
      '#type': number
      '#title': 'Your Score'
      '#description': 'Please provide your assessment of Drupal on this metric.&nbsp; Please grade on a scale of 1-10; 1 being Very Bad, and 10 being Excellent.'
      '#title_display': invisible
      '#maxlength': '3'
      '#required': true
      '#attributes':
        style: 'margin: 0;'
      '#min': '0'
      '#max': '999'
      '#step': '1'
  scores_true:
    '#type': checkbox
    '#title': 'I confirm I did the Matrix eval part of this form'
    '#required': true
    '#states':
      visible:
        - ':input[name="drupal_8_is_"]':
            value: 'A good CMS'
        - or
        - ':input[name="drupal_8_is_"]':
            value: 'A bad CMS'
    '#wrapper_attributes':
      style: 'padding-top: 20px;'
  expected_semester_of_graduation:
    '#type': textfield
    '#title': 'Random required text field at the end of Page 2'
    '#description': 'No conditional logic on this, just &#39;Required&#39;.&nbsp; Seen by everyone regardless of their answers to previous questions.'
    '#required': true
certificate_information:
  '#type': wizard_page
  '#title': 'Other Modules You May Like'
  ci_page_markup:
    '#type': markup
    '#display_on': both
    '#markup': '<div class="form-item webform-component webform-component-markup webform-component--certificate-information">Click the checkbox next to the module to see more information about the module.</div>'
  prek_4:
    '#type': checkbox
    '#title': Token
  prek_4_markup:
    '#type': markup
    '#states':
      visible:
        ':input[name="prek_4"]':
          checked: true
    '#display_on': both
    '#markup': 'Token is a very useful module, especially for populating webform data.'
  prek_8:
    '#type': checkbox
    '#title': 'CTools (CHAOS Tools)'
  prek_8_markup:
    '#type': markup
    '#states':
      visible:
        ':input[name="prek_8"]':
          checked: true
    '#display_on': both
    '#markup': 'Why isn&#39;t ALL OF THIS in Core, yet?'
  sped_712:
    '#type': checkbox
    '#title': 'Media (in Core)'
  sped_712_markup:
    '#type': markup
    '#states':
      visible:
        ':input[name="sped_712"]':
          checked: true
    '#display_on': both
    '#markup': 'Still needs work . . . But, is basically functional.&nbsp; It&#39;s the only way to go for Drupal 8.4 and up.'
jrockowitz’s picture

It is not reasonable to expect me to debug your custom webform. Please isolate the problem to a generic example.

jrwest_webguy’s picture

This is not a 'custom' webform. It is created solely from the elements and features provided by the Webform module for Drupal 8. I have trimmed the code down to just an example of the 'Page 2' logic; and I removed the cumbersome Flexbox layout elements. I am not asking you to fix my form. I'm simply asking you to look into why this form no longer works using the Webform module, where in the past it has.

start:
  '#type': wizard_page
  '#title': Start
  pi_page_markup:
    '#type': markup
    '#display_on': both
    '#markup': "<strong>This is how to reproduce the &#39;Illegal Choice&#39; error with Webforms 8.x-5.2.&nbsp; Here are some random fields to fill out.&nbsp; The problem starts on page 2.&nbsp; I&#39;ve tried this form on D8.6 and D8.7, using PHP7.0 and PHP7.2, all combos show error on page 2.</strong>\r\n<p>This form worked fine before upgrading to Webforms 8.x-5.2, I believe I was at 8.x-5.0 before.&nbsp; Also, &#39;the error&#39; does not show up if you run a &#39;Test&#39; on the form, it only shows up when you &#39;Manually&#39; fill out the form.<br />\r\n<br />\r\nThere is conditional logic on this page (Page 1) related to whether the TextArea for address is Editable, or if it is disabled and contains a message that the address is not different than Home Address, based on the answer to the &#39;Will you be living at your Address next year&#39;.</p>"
  first_name:
    '#type': textfield
    '#title': 'First Name:'
    '#required': true
applicant_status:
  '#type': wizard_page
  '#title': 'Drupal Status'
  drupal_8_is_:
    '#type': radios
    '#title': 'Drupal 8 is:'
    '#options':
      'A good CMS': 'A good CMS'
      'A bad CMS': 'A bad CMS'
      'What''s a Drupal?': 'What''s a Drupal?'
    '#required': true
  would_you_recommend_drupal_8_to_other_web_site_builders_:
    '#type': radios
    '#title': 'Would you recommend Drupal 8 to other web site builders?'
    '#options': yes_no
    '#required': true
    '#states':
      visible:
        ':input[name="drupal_8_is_"]':
          value: 'A good CMS'
  trad_yes_markup:
    '#type': processed_text
    '#states':
      visible:
        ':input[name="would_you_recommend_drupal_8_to_other_web_site_builders_"]':
          value: 'Yes'
    '#display_on': both
    '#text': "<p><strong>Good / Yes</strong> does not seem to be a problem, because it leads to exposure of other hidden elements, which MAY be the problem.&nbsp; (I am keenly suspicious of the 'Year' field, you will see shortly.)</p>\r\n"
    '#format': full_html
  trad_no_markup:
    '#type': processed_text
    '#states':
      visible:
        ':input[name="would_you_recommend_drupal_8_to_other_web_site_builders_"]':
          value: 'No'
    '#display_on': both
    '#text': "<p><strong>Good / No</strong> (you like Drupal but you would NOT recommend D8) does seem to be a problem, because it does not lead to exposure of hidden Year field, which I suspect might be the problem.</p>\r\n\r\n<p>I have also confirmed this TEST form does throw the error on my Drupal 8.6 / PHP 7.0 (Production) web server.&nbsp; I'm sure it will also throw the error on my Drupal 8.6 (or 8.7) / PHP 7.2 (Development) web server.</p>\r\n"
    '#format': full_html
  ntrad_markup:
    '#type': processed_text
    '#states':
      visible:
        ':input[name="drupal_8_is_"]':
          value: 'What''s a Drupal?'
    '#display_on': both
    '#text': "<p><strong>What's a Drupal? </strong>(and bad CMS) answered for 'Drupal 8 is:' both result in the user NOT being shown the 'Would you Recommend D8 . . .' question, which again leaves the 'Year' field hidden.</p>\r\n"
    '#format': full_html
  ug2grad:
    '#type': fieldset
    '#title': d8woke_track
    '#title_display': invisible
    '#states':
      visible:
        - ':input[name="would_you_recommend_drupal_8_to_other_web_site_builders_"]':
            value: 'Yes'
        - or
        - ':input[name="drupal_8_is_"]':
            value: 'A bad CMS'
    '#attributes':
      style: 'border: none;'
    what_versions_of_drupal_are_you_having_trouble_with_:
      '#type': select
      '#title': 'What versions of Drupal are you having trouble with?'
      '#options':
        6.x: 6.x
        7.x: 7.x
        8.x: 8.x
        9.x: 9.x
      '#states_clear': false
    ug2grad_markup:
      '#type': markup
      '#display_on': both
      '#markup': 'These elements in the d8woke_track Fieldset, appear or are hidden based on the following logic.&nbsp; If you answer <strong>Good / Yes</strong> or <strong>Bad / na</strong> to the &#39;Drupal 8 is&#39; and &#39;Would recommend . . .&#39; questions, respectively, at the top of Page 2 -- you will see the &#39;What version&nbsp; . . . &#39; select field.&nbsp; You will see the &#39;How long . . . &#39; and &#39;What year . . .&#39; questions ONLY if you choose Good / Yes.&nbsp; <strong>Good / Yes is really the only way to get past page 2.</strong>'
    sfe_planned:
      '#type': radios
      '#title': 'How long have you been working with Drupal?'
      '#options':
        'Less than 5 years': 'Less than 5 years'
        'More than 5 years': 'More than 5 years'
      '#states':
        visible:
          ':input[name="drupal_8_is_"]':
            value: 'A good CMS'
      '#states_clear': false
      '#default_value': None
    start_year:
      '#type': textfield
      '#title': 'What year did you start working with Drupal?'
      '#description': 'Please enter a 4-digit year.'
      '#help': 'What year will you begin attendance?'
      '#title_display': inline
      '#description_display': after
      '#minlength': '4'
      '#maxlength': '4'
      '#states':
        visible:
          ':input[name="drupal_8_is_"]':
            value: 'A good CMS'
          ':input[name="sfe_planned"]':
            checked: true
          ':input[name="would_you_recommend_drupal_8_to_other_web_site_builders_"]':
            '!value': 'No'
      '#attributes':
        style: 'width: 180px;'
  grad_track:
    '#type': fieldset
    '#title': wad_track
    '#title_display': invisible
    '#states':
      visible:
        ':input[name="drupal_8_is_"]':
          value: 'What''s a Drupal?'
    '#attributes':
      style: 'border: none;'
    the_rock_you_are_living_under_which_country_is_it_in_:
      '#type': textfield
      '#title': 'The rock you are living under, which country is it in?'
      '#required': true
  expected_semester_of_graduation:
    '#type': textfield
    '#title': 'Random required text field at the end of Page 2'
    '#description': 'No conditional logic on this, just &#39;Required&#39;.&nbsp; Seen by everyone regardless of their answers to previous questions.'
    '#required': true
certificate_information:
  '#type': wizard_page
  '#title': 'Other Modules You May Like'
  ci_page_markup:
    '#type': markup
    '#display_on': both
    '#markup': '<div class="form-item webform-component webform-component-markup webform-component--certificate-information">You made it to page 3, great no error!</div>'
jrockowitz’s picture

Status: Postponed » Needs review

The below element is causing this issue.

   sfe_planned:
      '#type': radios
      '#title': 'How long have you been working with Drupal?'
      '#options':
        'Less than 5 years': 'Less than 5 years'
        'More than 5 years': 'More than 5 years'
      '#states':
        visible:
          ':input[name="drupal_8_is_"]':
            value: 'A good CMS'
      '#states_clear': false
      '#default_value': None

The '#default_value': None is triggering the "An illegal choice has been detected. Please contact the site administrator." error because "None" is not listed in #options.

jrwest_webguy’s picture

Status: Needs review » Postponed

Thank you, Jacob. So, now I have a few more questions, if I may pick your brain. Can you elaborate on how you found this was the cause of the error? Did you use some kind of logging tool, web browser console utility, or just by reading the code?

jrockowitz’s picture

The #default_value of 'None' is not a valid option which triggers \Drupal\Core\Form\FormValidator::performRequiredValidation

For example, the below simplified element with trigger the validation error when no radio is selected.

sfe_planned:
  '#type': radios
  '#title': 'How long have you been working with Drupal?'
  '#options':
    'Less than 5 years': 'Less than 5 years'
    'More than 5 years': 'More than 5 years'
  '#default_value': None
jrockowitz’s picture

If you enjoy and value Drupal and the Webform module, get involved, consider joining the Drupal Association, and backing the Webform module's Open Collective.
jrwest_webguy’s picture

I would have never found that in a million millennia . . . I just looked at another Radio button element, and it has no '#default_value' line assigned to it; which tells me that #default_value is not required. So, I'm not even sure how it got in there . . . Anyway, thank you very much, again!

Guess this should have been in a separate issue? Is the ORIGINAL "StateAPI and multiple select fields" issue still prevalent in Drupal Core, or, more importantly, still a blocker for future Webform enhancements?

jrockowitz’s picture

Original issue is still in core.

jrockowitz’s picture

Title: Conditional logic with multiple entity references » [Drupal core] Conditional logic with multiple entity references
mhentry’s picture

Hi I am using Entity check boxes referencing taxonomy items. I want to create a condition with checkbox entity. Eg. let say my taxonomy has 5 items. A,B,C,D,E. I want to create a condition that when user select option B, they cant choose C,D and E. I could not know how to do a condition within entity checkbox. Any suggestions helpful.

jrockowitz’s picture

The Webform module's issue queue is for bugs, feature requests, and planning. Please post general support questions to Drupal Answers. You can also ask questions or help answer questions on the #webform channel on Drupal Slack.

You will most likely will have to write some custom JavaScript accomplish this behavior.

mhentry’s picture

Thank you for the reply. This is my YAML for entity checkbox, how do I get the value of each

delivery_options:
'#type': entity_checkboxes
'#title': 'Delivery Options'
'#target_type': taxonomy_term
'#selection_handler': 'default:taxonomy_term'
'#selection_settings':
target_bundles:
borrower_delivery_options: borrower_delivery_options
sort:
field: name
direction: ASC

Any examples on how to create custom JavaScript code code

(function($) {
$(document).ready(function() {
$('#delivery_options[4]').change(function() {
switch ($(this).val()) {
case '1':
$('#delivery_options[1]').hide();
break;
default:
$('#delivery_options[2]').show();
break;
}
});
});
}) (jQuery);

jrockowitz’s picture

@mhentry Please move this question/issue to https://drupal.stackexchange.com/questions/tagged/webforms

mhentry’s picture

@jrockowitz I moved it.

jrockowitz’s picture

Status: Postponed » Closed (outdated)