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

  1. Start with clean install of Drupal 10
  2. Add an integer list field (Select Field) to the Article content type with options: 1, 2, 3
  3. Add an integer text field (Text Field) to the Article content type
  4. 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"
  • Create a new Article
  • Enter "4" into Text Field
  • Select "1" for the Select Field
  • Select "2" for the Select Field
  • 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

    Command icon 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:

    Comments

    jmoreira created an issue. See original summary.

    jmoreira’s picture

    Issue summary: View changes
    jmoreira’s picture

    StatusFileSize
    new1.05 KB
    nonom’s picture

    StatusFileSize
    new1.07 KB

    I 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.

    jmester13’s picture

    I 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.

    jigish.addweb’s picture

    Assigned: Unassigned » jigish.addweb
    jigish.addweb’s picture

    sethfisher’s picture

    Here'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.

    hktang’s picture

    #8 works for me. Thank you!

    cicciobat’s picture

    Hi, 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 defined at 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.effect and not effect.effect ?

    cicciobat’s picture

    I have attached a possible patch, let me know if it works and is okay.

    cicciobat’s picture

    Please, ignore the previous one since it was made from a project root, this one shuld works. Thanks.

    er.garg.karan made their first commit to this issue’s fork.

    benstallings made their first commit to this issue’s fork.

    ethant made their first commit to this issue’s fork.

    joelpittet made their first commit to this issue’s fork.

    joelpittet’s picture

    Hiding patch files, let's concentrate on the MR. I rerolled it to get it up to date.

    joelpittet’s picture

    Status: Needs review » Fixed
    StatusFileSize
    new204.05 KB

    Fixed 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:empty never 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 its 400ms default. Both paths now hand handlers the same {effect, options} shape, and getEffect() flattens to the applied effect's options, which also revived the numeric conversion that had been iterating over arrays and doing nothing!

    New FunctionalJavascript coverage for the fill value and its restore, and for the configured fade speed, plus unit coverage of getEffect().

    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.
    smoke test

    Now that this issue is closed, review the contribution record.

    As a contributor, attribute any organization that helped you, or if you volunteered your own time.

    Maintainers, credit people who helped resolve this issue.

    joelpittet’s picture

    Assigned: jigish.addweb » Unassigned