Problem/Motivation
Note: The original description (below) used a different combination of field types but a simple Select field and Text field illustrate the problem nicely.
Steps to Reproduce
- Start with clean install of Drupal 10
- Add an integer list field (Select Field) to the Article content type with options: 1, 2, 3
- Add an integer text field (Text Field) to the Article content type
- Add a dependency: Text Field is filled with a value when Select Field has value "1"
- Enter "1" for "Fill field with a value effect option: value"
- Check "Restore previous value when untriggered"
Expected result
- Text Field value is set to 1 when Select Field is "1"
- Text Field value is set back to "4" when Select Field is "2"
Actual result
- Text Field value is unchanged when Select Field is "1"
Original report by StG
| Comment | File | Size | Author |
|---|---|---|---|
| #20 | conditional-fields-filled.gif | 204.05 KB | joelpittet |
Issue fork conditional_fields-3357431
Show commands
Start within a Git clone of the project using the version control instructions.
Or, if you do not have SSH keys set up on git.drupalcode.org:
- 3357431-filled-with-a
changes, plain diff MR !89
- 3357431-fill-reroll
changes, plain diff MR !101
Comments
Comment #2
jmoreira commentedComment #3
jmoreira commentedComment #4
nonom commentedI was debugging #3 because wasn't working for me. It seems the value to fill was in e.effect.options.fill instead e.effect.fill.
Once replaced the e.effect.fill references by e.effect.options.fill it worked.
Thanks, patch attached.
Comment #5
jmester13 commentedI tried this patch with moderation state and found it does not address that functionality.
Example:
Boolean is required when Moderation State is In Review.
Following for suggestions and ideas.
Comment #6
jigish.addweb commentedComment #7
jigish.addweb commentedComment #8
sethfisher commentedHere's a new version of the patch which fixes an issue I found. If you edit an existing node with a pre-existing value in the target field, choosing the triggering value will set the target field to the pre-existing value rather than the value that's supposed to be triggered.
Comment #9
hktang commented#8 works for me. Thank you!
Comment #10
cicciobat commentedHi, I have a select list that controls two other field and make them visible when a option is matched, whit this patch the first of the two field is shown but the second one none, in console this error is shown:
Uncaught ReferenceError: effect is not definedat line 115 of conditional_fields.js.If I try to print out the effect variable, actually is undefined, have any idea? May it should be
e.effectand noteffect.effect?Comment #11
cicciobat commentedI have attached a possible patch, let me know if it works and is okay.
Comment #12
cicciobat commentedPlease, ignore the previous one since it was made from a project root, this one shuld works. Thanks.
Comment #19
joelpittetHiding patch files, let's concentrate on the MR. I rerolled it to get it up to date.
Comment #20
joelpittetFixed in 4.x, merge train 🚂 left the station. Thanks all, and especially @nonom in #4 for the diagnosis and @sethfisher in #8 for spotting the restore behaviour.
The problem turned out to be wider than the fill case: effect options are stored keyed by effect name and nothing in the JS ever read them that way. So
state:emptynever saw the fill value, "Restore previous value when untriggered" was not read at all, and the fade/slide speed was always undefined... jQuery quietly fell back to its400msdefault. Both paths now hand handlers the same{effect, options}shape, andgetEffect()flattens to the applied effect's options, which also revived the numeric conversion that had been iterating over arrays and doing nothing!New
FunctionalJavascriptcoverage for the fill value and its restore, and for the configured fade speed, plus unit coverage ofgetEffect().gif below: filling the control field sets the target to the configured value, clearing it restores what was typed, and the fade target takes the configured 5 seconds.

Comment #23
joelpittet