Conditional computed ajax fields does not trigger visibility of other fields anymore

Created on 1 March 2024, 4 months ago
Updated 14 March 2024, 4 months ago

Problem/Motivation

We upgraded a platform from Webform 6.1.4 to 6.2.2 and Drupal 9.5.8 to 10.2.2. After the upgrade, the conditional computed ajax fields does still work as expected, but the visibility condition related to this computed value is not triggered anymore.

I uploaded two videos to show the behavior:
Webform-D9-Example.mp4 - We can see how the value of the field older_than_18 gets updated with ajax and the email/phone fields becomes visible.
Webform-D10-Example.mp4 - We can see how the value of the field older_than_18 gets updated with ajax but the email/phone fields becomes NOT visible.

Looks like the form #states are not updated/triggered.

I'm not sure is this problem related to Webforms or Drupal core changes.

Steps to reproduce

This is an example of the form with the computed_twig field named older_than_18 and the related field parent_consent with the invisible state:

elements:
  messages:
    '#type': status_messages
note:
  '#type': textarea
  '#title': Note
  '#title_display': after
  '#required': true
birthday:
  '#type': date
  '#title': 'Date de naissance *'
  '#required': true
  '#title_display': after
  '#mapping': '{"tocco":"User|paths|birthdate"}'
  '#format': date_courte_webform
older_than_18:
  '#type': computed_twig
  '#title': older_than_18
  '#mode': html
  '#template': "{{ (date(data.birthday) < date('-18years') or data.birthday is empty) ? 'Yes' : 'No' }}"
container:
  '#type': container
  parent_consent:
    '#type': checkboxes
    '#title': 'Accord des parents'
    '#title_display': invisible
    '#options':
      'my parents agree': 'Mes parents sont d'accord que je participe au cours'
    '#states':
      invisible:
        ':input[name="older_than_18"]':
          '!value': 'Yes'
  parent_email:
    '#type': email
    '#title': 'E-Mail parents *'
    '#required': true
    '#states':
      visible:
        ':input[name="older_than_18"]':
          value: 'No'
  parent_phone:
    '#type': tel
    '#title': 'Téléphone parents *'
    '#title_display': after
    '#required_error': 'Telefonnummer der Eltern ungültig'
    '#states':
      visible:
        ':input[name="older_than_18"]':
          value: 'No'
    '#international': true
    '#international_initial_country': CH
    '#telephone_validation_format': '0'
    '#required': true
actions:
  '#type': webform_actions
  '#title': 'Submit button(s)'
  '#submit__label': "S'inscrire"
🐛 Bug report
Status

Closed: outdated

Version

6.2

Component

Code

Created by

🇨🇭Switzerland weri

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

Comments & Activities

  • Issue created by @weri
  • 🇧🇪Belgium Jonne

    We are experiencing the same. In my research I found that the computed field is indeed calculated but the problem lies in the fact that the conditions to show the field doesn't trigger visibility.

  • 🇺🇸United States dswier

    I recently ran into this issue in the process of testing our upgrade to D10.2. My use case is the very same as the initial post. We are calculating if the user is over 18, and if not we display the parent/guardian information fields. The logic in our computed twig field is slightly different, but the result is the same. Instead of saving a yes/no value, the value of our field was markup saying "Please provide the name of a Parent/Guardian". We had also been using the computed_twig field being "filled" as the condition for displaying the other fields. Just like OP, this stopped working between 9.5 and 10.2. In troubleshooting, I did also try checking for a value from the computed field, but that didn't work either. What I did see was that if my condition was the value being empty, the parent/guardian fields would always display. Therefore, my conclusion was that these computed fields don't seem to have a value that is available to the #states system anymore. We haven't found a workaround yet, but I don't have a full understanding of all the systems at work yet.

  • 🇧🇪Belgium Jonne

    I could resolve the issue this afternoon by updating my Drupal installation from 10.2.2 to 10.2.4. No related contrib modules received any updates in the process of updating everything, so I'm pretty sure this is related to a fix in core. I hope this helps the both of you.

  • 🇺🇸United States dswier

    Thanks for your comment, @Jonne! We were also on Drupal 10.2.2, so I updated, and that did indeed solve the issue for us.

  • Status changed to Closed: outdated 4 months ago
  • 🇺🇸United States cilefen

    I guess this is a duplicate of some core bug, or outdated.

  • 🇨🇭Switzerland weri

    Thank you for all the feedbacks!

    I can confirm that an update to core 10.2.4 solves the problem.

Production build 0.69.0 2024