Using a token with a default value on a "Checkboxes other" causes other to be checked if the token value is empty

Created on 8 October 2024, 2 months ago

If I use a token like [webform_submission:user:field_myoption:clear] to set the default value on a "Checkboxes other" field type and the user does not have a value in their account for that field or if the user is an anonymous user then the other option is checked and the other field is displayed empty.

πŸ› Bug report
Status

Active

Version

6.2

Component

Code

Created by

πŸ‡ΊπŸ‡ΈUnited States jphelan

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Merge Requests

Comments & Activities

  • Issue created by @jphelan
  • πŸ‡ΊπŸ‡ΈUnited States jphelan

    Example source

    flexbox:
      '#type': flexbox
      first_name:
        '#type': textfield
        '#title': 'First Name'
        '#required': true
        '#default_value': '[webform_submission:user:first_name:clear]'
      last_name:
        '#type': textfield
        '#title': 'Last name'
        '#required': true
        '#default_value': '[webform_submission:user:last_name:clear]'
    email:
      '#type': email
      '#title': Email
      '#required': true
      '#default_value': '[webform_submission:user:mail:clear]'
    address:
      '#type': address
      '#title': Address
      '#required': true
      '#default_value':
        country_code: US
        langcode: ''
        address_line1: '[webform_submission:user:mailing_address:address_line1:clear]'
        address_line2: '[webform_submission:user:mailing_address:address_line2:clear]'
        locality: '[webform_submission:user:mailing_address:locality:clear]'
        administrative_area: '[webform_submission:user:mailing_address:administrative_area:clear]'
        postal_code: '[webform_submission:user:mailing_address:postal_code:clear]'
        given_name: null
        additional_name: null
        family_name: null
        organization: null
        sorting_code: null
        dependent_locality: null
      '#field_overrides':
        givenName: hidden
        additionalName: hidden
        familyName: hidden
        organization: hidden
        addressLine1: optional
        addressLine2: optional
        postalCode: optional
        sortingCode: optional
        dependentLocality: hidden
        locality: required
        administrativeArea: required
    how_did_you_hear_about_this_meeting_:
      '#type': checkboxes_other
      '#title': 'How did you hear about this meeting?'
      '#options':
        'Social Media': 'Social Media'
        'Support Group': 'Support Group'
        'Web Search i.e. Google or Bing Search': 'Web Search i.e. Google or Bing Search'
        'Web Ad i.e. Paid Text Ad or Graphic Ad': 'Web Ad i.e. Paid Text Ad or Graphic Ad'
        'Post Card': 'Post Card'
      '#required': true
      '#default_value':
        - '[webform_submission:user:how_you_found_us:clear]'
    actions:
      '#type': webform_actions
      '#title': 'Submit button(s)'
  • πŸ‡ΊπŸ‡ΈUnited States jrockowitz Brooklyn, NY

    The attached webform is simplified example that replicates the bug.

  • πŸ‡ΊπŸ‡ΈUnited States jrockowitz Brooklyn, NY
  • Pipeline finished with Success
    27 days ago
    Total: 382s
    #348804
  • πŸ‡ΊπŸ‡ΈUnited States jphelan

    I tired the patch from here but the other checkbox is still checked for me.
    https://git.drupalcode.org/project/webform/-/merge_requests/559/diffs

  • Pipeline finished with Canceled
    18 days ago
    Total: 139s
    #358272
  • πŸ‡ΊπŸ‡ΈUnited States jrockowitz Brooklyn, NY

    Let's try a different approach which should be safer and more reliable.

  • Pipeline finished with Success
    18 days ago
    Total: 447s
    #358273
  • πŸ‡ΊπŸ‡ΈUnited States jphelan

    That new patch works for me! Other is no longer checked.

  • Pipeline finished with Skipped
    15 days ago
    #361934
  • Pipeline finished with Skipped
    15 days ago
    #361935
  • πŸ‡ΊπŸ‡ΈUnited States jrockowitz Brooklyn, NY
  • πŸ‡ΊπŸ‡ΈUnited States jrockowitz Brooklyn, NY
  • Status changed to Fixed 12 days ago
Production build 0.71.5 2024