Conditional element checking too many times, comparing against empty value

Created on 5 June 2023, over 1 year ago
Updated 13 September 2023, over 1 year ago

Problem/Motivation

We have text message on webform that should show if user does have certain roles. it's defined in field markup_not_on_maintenance field in below example with "Conditional logic" setting.

What happens is that the message is still shown:
β†’

In my local setup I see that the check is done 3 times.

I've put this debug code in js/webform.states.js
β†’

And in browser console I see the value is empty after first check:
β†’

Steps to reproduce

In our system we have user with special roles and we create hidden input with token [current-user:roles:join:,]

For this demo purpose, I'll give a minimal webform with hard-coded values for control_user_roles field:

control_user_roles:
  '#type': hidden
  '#title': 'Control user roles'
  '#value': 'authenticated,ts_maintenance_user,tsd_maintenance_user,tedds_maintenance_user'
type_of_request:
  '#type': radios
  '#title': 'Type of request'
  '#title_display': invisible
  '#prepopulate': true
  '#options':
    support: 'I have  a support request'
    feedback: 'I have feedback about a product or service'
  '#required': true
  '#required_error': 'Please select an item'
markup_not_on_maintenance:
  '#type': markup
  '#states':
    visible:
      ':input[name="type_of_request"]':
        value: support
      ':input[name="control_user_roles"]':
        value:
          '!pattern': '(?:ts|tsd|tedds|epm)_maintenance_user|ts_(?:carbon|graphite|diamond)_user'
      ':input[name="control_user_organization"]':
        '!value': '-'
  '#wrapper_attributes':
    class:
      - info-box
  '#markup': |-
    <h3>Hmm, do you have an active subscription or maintenance contract?</h3>

    <p>Looks like your current user ID is not connected with a subscription license or a valid maintenance contract. You can still contact our support, but we may not be able to help you.</p>

Proposed resolution

The message should not show and I think that check should not be done 3 times.

If you'd add a hack, something like this to js/webform.states.js, then the form works fine:

    else if ('!pattern' in reference) {
      if (value === null) {
        value = 'authenticated,ts_maintenance_user,tsd_maintenance_user,tedds_maintenance_user';
      }
      console.log(reference['!pattern']);
      console.log(value);
      return !((new RegExp(reference['!pattern'])).test(value));
    }
πŸ› Bug report
Status

Needs work

Version

6.2

Component

Code

Created by

πŸ‡ͺπŸ‡ͺEstonia hkirsman

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

Comments & Activities

Production build 0.71.5 2024