Conditionally preselect radio button in Drupal Webforms YAML

65 views Asked by At

I am trying conditionally preselect a radio button in Drupal Webforms (I assume this has to be done with YAML?). I have a hidden field "ref" which can have 1 of 4 values (de, fr, it, en). Depending on what value "ref" has when the page loads, I want the respective radio button from "language" to be selected. below is what I tried, but the condition doesn't work, I don't think the syntax is right, I just used "-condition" to depict what I am aiming for.

language:
  '#type': radios
  '#title': Language
  '#options':
    de: de
    fr: fr
    it: it
    en: en
  '#default_value': de
      - condition: 
        ':input[name="ref"]': 
        value: de
  '#default_value': fr
      - condition: 
        ':input[name="ref"]': 
        value: fr
  '#default_value': it
      - condition: 
        ':input[name="ref"]': 
        value: it
  '#default_value': en
      - condition: 
        ':input[name="ref"]': 
        value: en
  '#access_create_roles':
    - authenticated
    - anonymous
  '#access_update_roles':
    - authenticated
    - anonymous
  '#access_view_roles':
    - authenticated
    - anonymous
ref:
  '#type': hidden
  '#title': ref
  '#default_value': de
  '#access_create_roles':
    - authenticated
    - anonymous
  '#access_update_roles':
    - authenticated
    - anonymous
  '#access_view_roles':
    - authenticated
    - anonymous
0

There are 0 answers