Incorrect Formating of selector key in dependency of a value from control field

Created on 17 January 2021, almost 4 years ago
Updated 28 September 2023, about 1 year ago

Problem/Motivation

I'm having an issue in one of the fields where the field is a multivalue select list and its first option key is coincidentally a substring of the field's machine name as follows:
field name: field_responsibility
first option: sp|Social platform
last option: other|Other
and I want to show some other field when the user chooses the "other" option. I added the dependency but nothing happened in the form and the field was still visible. After some debugging, I found that in OptionsButtons.php there's a str_replace statement that doesn't work in this case.

$selector_key = str_replace($field['#return_value'], current($value), $selector);

Since the $selector value is [name="field_responsibility[sp]"] str_replaces outputs the incorrect value [name="field_reotheronsibility[other]"] where the correct output for the condition to work is [name="field_responsibility[other]"]

Steps to reproduce

  • Create a multivalue text list field (FIELD_1) -> List (text) unlimited
  • Add list options to the field where the first option's key is a substring of the fields machine name
    • Change the form display of the field to be "Check boxes/radio buttons"
  • Create another field (FIELD_2) to be dependant on the multivalue field FIELD_1
  • In manage dependencies, set target field to be FIELD_2, control field = FIELD_1, target field is "visible" when the control field "has a value", hit add dependency
  • set Values input mode to "insert value from widget"
  • select any option except the first one
  • Go to the form page and you should see that FIELD_2 is not hidden and doesn't apply the condition correctly
πŸ› Bug report
Status

Needs work

Version

4.0

Component

Code

Created by

πŸ‡―πŸ‡΄Jordan mhawwari

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.

Production build 0.71.5 2024