I am still having problems in getting my form to work correctly. The YAML file is included.
I have generated a field with a computed twig result.
I then try to use this as a condition to make visible a selection list.
If I use value is then nothing happens
If I use value is not then "I can get it to display
The relevant sections are highlighted in blue
If you can help this would be great

Comments

riverrat created an issue. See original summary.

jrockowitz’s picture

Status: Active » Postponed (maintainer needs more info)

Please isolate a simpler example, export and attach your webform as YAML (and not a PDF document).

riverrat’s picture

Status: Postponed (maintainer needs more info) » Active

I have made it as simple as I can
There is no download button on the source so I have copied and pasted it here
Really appreciate your thoughts

personal_details:
  '#type': wizard_page
  '#title': 'Personal details'
  '#access_create_roles':
    - authenticated
  competition_date:
    '#type': date
    '#title': 'Competition date'
    '#title_display': invisible
    '#description_display': invisible
    '#disabled': true
    '#prepopulate': true
    '#default_value': '2020-06-22'
    '#label_attributes':
      style: 'background: blue ;'
  dob:
    '#type': date
    '#title': 'Date of Birth'
    '#attributes':
      style: 'font-color:red;'
    '#format': html_date
    '#min': 01/01/1930
    '#max': 01/01/2013
    '#datepicker': true
    '#date_date_format': m/d/Y
age_calc:
  '#type': wizard_page
  '#title': 'Age calc'
  age_display:
    '#type': computed_twig
    '#title': 'Your age at the start of the competition'
    '#title_display': inline
    '#prepopulate': true
    '#value': |
      {% set age_sel = data.competition_date - data.dob %}
      {{ age_sel }}
  age_cat:
    '#type': computed_twig
    '#title': 'Age category'
    '#access_create_roles':
      - authenticated
    '#value': |
      {% set age = (data.competition_date - data.dob) %}
      {% if age >= '55' %}
        {{ 'veteran' }}
        {% elseif age < '55' and age > '18' %}
          {{ 'adult' }}
        {% elseif age == '17' or ge == '18' %}
          {{ 'young adult' }}
        {% elseif age >= '13' and age <= '16' %} 
          {{ 'junior' }}
        {% elseif age <= '12' %}
          {{ 'cub' }}
        {% else %}
          {{ 'wrong category' }}
      {% endif %}
bow_style:
  '#type': wizard_page
  '#title': 'Bow style'
  '#open': true
  '#access_create_roles':
    - authenticated
  veteran_bow_styles:
    '#type': select
    '#title': 'Veteran, young adult or junior bow styles'
    '#options': v_y_j_bow_style
    '#required': true
    '#states':
      visible:
        - ':input[name="age_cat"]':
            value: veteran
        - xor
        - ':input[name="age_cat"]':
            value: 'young adult'
        - xor
        - ':input[name="age_cat"]':
            value: junior
  adult:
    '#type': select
    '#title': Adult
    '#options': bow_style
    '#required': true
    '#states':
      visible:
        ':input[name="age_cat"]':
          value: adult
  cub_bow_styles:
    '#type': select
    '#title': 'Cub bow styles'
    '#options': cub_bow_style
    '#states':
      visible:
        ':input[name="age_cat"]':
          value: cub
    '#required': true
jrockowitz’s picture

You need to wrap your twig in Twig spaceless block.

Use the spaceless tag to remove whitespace between HTML tags, not whitespace within HTML tags or whitespace in plain text:

age_cat:
    '#type': computed_twig
    '#title': 'Age category'
    '#access_create_roles':
      - authenticated
    '#value': |
      {% spaceless %}
      {% set age = (data.competition_date - data.dob) %}
      {% if age >= '55' %}
        {{ 'veteran' }}
        {% elseif age < '55' and age > '18' %}
          {{ 'adult' }}
        {% elseif age == '17' or ge == '18' %}
          {{ 'young adult' }}
        {% elseif age >= '13' and age <= '16' %} 
          {{ 'junior' }}
        {% elseif age <= '12' %}
          {{ 'cub' }}
        {% else %}
          {{ 'wrong category' }}
      {% endif %}
      {% endspaceless %}
jrockowitz’s picture

...but I think spaceless should be setting that is available via the UI.

jrockowitz’s picture

Version: 8.x-5.0-rc16 » 8.x-5.x-dev
Status: Active » Needs review
StatusFileSize
new4.75 KB
new83.9 KB

The attached patch supports trim and spaceless. Spaceless trims and removes space between HTML tags.

riverrat’s picture

Version: 8.x-5.x-dev » 8.x-5.0-rc16
Status: Needs review » Active

I can't believe that it works, but it does which is no reflection on you but after a great deal of effort on my behalf with no results
I have not yet applied the patch, but will do soon
Thanks a million I can now create a registration form where there is little chance of people making errors

jrockowitz’s picture

Status: Active » Needs review
StatusFileSize
new5.2 KB

This is patch is a little cleaner.

Status: Needs review » Needs work

The last submitted patch, 8: 2982860-8.patch, failed testing. View results

jrockowitz’s picture

Status: Needs work » Needs review
StatusFileSize
new5.2 KB
riverrat’s picture

Status: Needs review » Active

Patch applied and everything works as predicted
Thanks again

jrockowitz’s picture

Status: Active » Reviewed & tested by the community
dinesh18’s picture

#10 patch applies cleanly and looks good.
+1 to RTBC

  • jrockowitz committed bcd6569 on 8.x-5.x
    Issue #2982860 by jrockowitz, riverrat: Computed twig value in...

  • jrockowitz committed 5e7e645 on 8.x-5.x
    Revert "Issue #2982860 by jrockowitz, riverrat: Computed twig value in...
  • jrockowitz committed a9e088e on 8.x-5.x
    Issue #2982860 by jrockowitz, riverrat: Computed twig value in...
jrockowitz’s picture

Status: Reviewed & tested by the community » Fixed

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.