Computed twig with conditional visibility is never shown

Created on 11 August 2020, over 4 years ago
Updated 28 February 2024, 10 months ago

Problem/Motivation

IK have a computed twig element, ajax enabled, that has a conditional visibility on another fields value. The computed twig is calculated correctly and shown very briefly before disappearing again.

Steps to reproduce

See below YAML for the form elements:

jouw_gift:
  '#type': number
  '#title': 'Jouw gift'
  '#field_prefix': '€ '
  '#default_value': '40'
  '#min': 40
  '#step': 1
variabele_steun_tekst:
  '#type': computed_twig
  '#title': 'Variabele steun tekst'
  '#title_display': none
  '#states':
    visible:
      ':input[name="jouw_gift"]':
        value:
          greater: '59'
  '#display_on': form
  '#template': |
    {% set aantal = data.jouw_gift // 60 %}
    {% if aantal == 1 %}
    {% set werkwoord = 'kan' %}
    {% set kinderen_label = 'kind' %}
    {% set jongeren_label = 'jongere' %}
    {% else %}
    {% set werkwoord = 'kunnen' %}
    {% set kinderen_label = 'kinderen' %}
    {% set jongeren_label = 'jongeren' %}
    {% endif %}
    <p>Hiermee {{ werkoord }} {{ aantal }} {{ kinderen_label }} of {{ jongeren_label }} op medisch begeleide vakantie.<p>
    
  '#ajax': true

Proposed resolution

I think the conditional behaviour is not executed after the computed element has reloaded on ajax event. Wouldn't know where to start searching to get this fixed...

Remaining tasks

Everything...

User interface changes

None

API changes

None?

Data model changes

None

πŸ› Bug report
Status

Fixed

Version

5.19

Component

Code

Created by

πŸ‡§πŸ‡ͺBelgium weseze

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

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

  • πŸ‡ΊπŸ‡ΈUnited States papagrande US West Coast

    I ran into this issue on a client site that was spewing "User error: "update" is an invalid render array key in Drupal\Core\Render\Element::children() (line 98 of /var/www/html/web/core/lib/Drupal/Core/Render/Element.php)" PHP errors because of conditional visibility settings on a computed twig element. Implementing the workaround in #3 removed the errors.

Production build 0.71.5 2024