When multiple fields have a conditional pattern on a multi select, only the last is considered valid

Created on 31 January 2023, almost 2 years ago
Updated 20 July 2023, over 1 year ago

Problem/Motivation

When you want to have an extra field appear for every option in a multi-select and you use the pattern matching option, it will work in the front end, but webform will ignore the values of all those extra fields, except the last one whose pattern matched.

Steps to reproduce

- Create a multiselect field with values "foo" and "bar".
- Create a text field with a condition of visible, using the pattern "foo" on the multiselect, leave "Clear value(s) when hidden" checked.
- Create a text field with a condition of visible, using the pattern "bar" on the multiselect, leave "Clear value(s) when hidden" checked.
- Go to the form, select both "foo" and "bar" from the multiselect. Note how both the text fields appear.
- Fill out both text fields & submit.
- Go to the submissions and note how only the value of the second text field is included.
- Go back to the text fields and uncheck "Clear value(s) when hidden".
- Set up a mail handler to mail the [webform_submission:values] token.
- Go to the form, select both "foo" and "bar" from the multiselect, fill out both text fields & submit.
- Go to the submissions and note how the values of both text fields are included.
- Check the mail and note how only the value of the second text field is included.

Proposed resolution

Don't overwrite the result in WebformSubmissionConditionsValidator->checkCondition if it's already 1.

Remaining tasks

Add test.

User interface changes

n/a

API changes

n/a

Data model changes

n/a

πŸ› Bug report
Status

Closed: cannot reproduce

Version

6.1

Component

Code

Created by

πŸ‡§πŸ‡ͺBelgium seutje Antwerp

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

Comments & Activities

  • Issue created by @seutje
  • πŸ‡§πŸ‡ͺBelgium seutje Antwerp
  • Status changed to Needs review almost 2 years ago
  • πŸ‡§πŸ‡ͺBelgium seutje Antwerp
  • Status changed to Needs work almost 2 years ago
  • πŸ‡§πŸ‡·Brazil renatog Campinas

    Thank you @seutje

    Now, reading your explanation can be clear, but in the future the person that will read the code if ($trigger_result !== FALSE && $result !== 1) { can be confused. Based on that, do you mind putting one simple comment explaining, please?

  • Status changed to Needs review almost 2 years ago
  • πŸ‡§πŸ‡ͺBelgium seutje Antwerp

    Sure.

  • Status changed to Postponed: needs info over 1 year ago
  • πŸ‡ΊπŸ‡ΈUnited States jrockowitz Brooklyn, NY

    I am not able to replicate this issue using the attached webform. The multiselect's conditional logic is not working as expected. There might be another issue that may need to be addressed.

      select:
        '#type': select
        '#title': select
        '#multiple': true
        '#options':
          foo: foo
          bar: bar
      foo:
        '#type': textfield
        '#title': foo
        '#states':
          visible:
            ':input[name="select[]"]':
              value: foo
      bar:
        '#type': textfield
        '#title': bar
        '#states':
          visible:
            ':input[name="select[]"]':
              value: bar
    
  • Status changed to Closed: cannot reproduce over 1 year ago
  • πŸ‡ΊπŸ‡ΈUnited States jrockowitz Brooklyn, NY

    Please reopen when an example webform can be provided.

Production build 0.71.5 2024