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 7.36 and conditional fields 7.x-3.x-dev (http://simplytest.me/)
  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" (Screenshot 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" (Screenshot 2)

    Original report by StG

    Hello,

    I'm not totally sure: wheter it's a bug or it's just a user error: The entity is a node, the dependee is a simple true/false field, the dependent field is a list with several textual options. I'd like to fill this field with a value when the dependee is checked, thus I set the condition to 'value', the input mode to 'insert value form widget' and I checked to only option. If I set the form state of dependent to visible or invisible everything works as intended, the dependent field appeares or disappears as the dependee checked. But if I chose the 'filled with a value' form state (that's what I actually need) nothing happens. I added to the value field the 'key' of the desired list item.

    Support from Acquia helps fund testing for Drupal Acquia logo

    Comments

    StG’s picture

    Title: 'Filled with a value' form stat seems broken » 'Filled with a value' form state seems broken

    Reason of edit: typos

    Rob de Koter’s picture

    I have the same problem, if the "Dependent" field hat the value "10" the "Dependee" should get the value "12", nothing happened.
    If I change the "dependee" from "Filled with a value" to "Hide" all works fine.
    Just to make sure I tried this on an other Drupal 7 install and a Linux instead of a Windows server unfortunately the result was the same.
    I am wondering if the browser or the OS could have something to do with it.
    I just installed a fresh version of Drupal 7.26 with as only extra module the "Conditional Fields" module, unfortunately it still does not work: Acquia Dev Desktop and IE 11 and Firefox 26

    johnhorner’s picture

    I'm finding the same thing. Other options work, e.g. "visible when dependee has a certain value" or "disabled when dependee has a certain value", but not the "filled when dependee has a certain value" option.

    joco_sp’s picture

    Has anyone found the solution for this?

    bourgeoy’s picture

    I am still having this issue, hoping for a solution! None of the fixes I've read about so far have helped...

    j4’s picture

    I am also facing this issue in a brand new installation. Some help please!

    Duplicate of https://www.drupal.org/node/2270775

    dstorozhuk’s picture

    Have the same problem. Looks like the "filled with a value" doesn't work.

    Maurice M.’s picture

    Im also trying to do this, doesn't work.

    kutagh’s picture

    Hello,

    We wanted to utilize this feature as well, but ran in the same issue. I have been asked to investigate this issue and if possible to fix it.
    Unfortunately, I have been unable to pinpoint the location of the code implementation for the feature to fill a value in the dependent (or to empty it), which leads me to believe that this feature has not been implemented whatsoever.

    It is currently unlikely that I will be implementing this feature, but I do hope that someone will.

    jeramy’s picture

    Same issue. I am a bit surprised since this seems pretty fundamental. Seeing there has not been a commit on this module in a year, my hopes are not high for a resolution though. Has anyone found an alternative?

    elgandoz’s picture

    Apparently JQuery update (in my case 7.x-2.5) breaks CF. Disabling it solved this issue. See https://www.drupal.org/node/2122619

    damianpollard’s picture

    Hi elgandoz. I am having the same problem and I already have JQuery update disabled. Do I need to uninstall JQuery update to fix the problem?

    funkeyrandy’s picture

    same issue here with our without jquery update

    draenen’s picture

    Title: 'Filled with a value' form state seems broken » 'Filled with a value' form state is broken
    Issue summary: View changes
    FileSize
    105.16 KB
    116.17 KB

    Added steps to reproduce.

    draenen’s picture

    Further investigations showed that "fill with a value" is implemented as an effect (like fade in/out etc) and all effects seem to be broken it the latest release. See #2466187: Effects doesn't work

    draenen’s picture

    Status: Active » Needs review
    FileSize
    1.03 KB

    I tested this patch with the steps in the description. The issue is that Drupal states.js does not bind the 'empty' state by default so the fill effect was not triggered.

    jwineichen’s picture

    #16 patch worked for me!

    bijbij’s picture

    Hi dear draenen
    I have used your patch(#16)
    But it is not working for me even after applying #16 patch .

    help me please.

    draenen’s picture

    bijbij, could you tell me what field types you are using in the dependency?

    For example: "a text field is filled with a value when a select field has a value".

    Darshi Shah’s picture

    Hi

    #16 dont work for me. I want it to fill value in one select list based on another. I tried using text field as well but it doesnt work.

    - Darshi

    funkeyrandy’s picture

    im using two integer text fields....text field 1 should be set to 55 if textfield 2 is set to 99....no change, patch #16 implemented...jquery turned on as well as disabled

    please help

    MrPeanut’s picture

    Patch from #16 applies cleanly, but does not work for me either.

    In my case, I am trying to set the value of a Long text field that is dependent on the value of a List (text) field. (For example, if the I choose "Service" in the select list, it puts "Please enter your service request" in the long text field.)

    agsh’s picture

    #16 patch worked for me.

    jQuery update enabled (jQuery version by default: 1.10).

    eigentor’s picture

    For me #16 worked.
    I changed the two lines manually, since the patch did not apply.
    No Jquery update installed in my case.

    ramdhanh’s picture

    Vote for #16. Applied that one and solved my issue. Thanks.

    cosolom’s picture

    #16 worked for me too

    GAMe’s picture

    16 didnt work for me either Im trying to display a text field if a link field has a value. :-(

    eigentor’s picture

    Just a tip for those that need some advanced conditional fields features and sometimes hitting their head against a brick wall: One can perfectly - and sometimes more flexibly - code this functionality by hand.
    I once had to to this because conditional fields caused some weird error and I was suprised how well it worked.
    The trick is to not set fields as required and build a validation function oneself.
    The conditional fields module does it the other way round by catching all the error messages thrown by required fields and unsetting the messages which leads to not making the fields required. This more complicated than not making a field required in the first place.
    So in your validation function, you can set the field as required and do all kinds of fancy stuff.

    While required fields are not the topic of this issue it is the problem that normally causes the most headache when you try to not use the module while getting the same functionality.
    The #states property of forms of the forms api comes in handy: it allows to check if a field is checked or contains a certain value, which is Javascript, from php code.
    https://api.drupal.org/api/examples/form_example!form_example_states.inc...

    jhoffmcd’s picture

    So I thought I had this working, but when pushed to production, something is different and it's not working. When I run the site locally, everything is fine and the patch does work. There is some other factor that is causing this to work/not-work for everybody. If I find it I'll try and refactor a patch and load it up.

    FYI both env run jQuery 1.10.2.

    hondaman900’s picture

    Any updates on this issue? I'm stuck and have an entityForm where, depending on the select list option selected, a value is put in another textbox integer field. As stated by others above, this doesn't work (though make visible with same conditions does work).

    Any solutions/workarounds for this...?

    Mr. Red’s picture

    #16 patch worked for me.
    jQuery update enabled (jQuery version by default: 1.10).

    pamelalies’s picture

    Interestingly, I got the patch to work if I added the first line - the additional bind state, but left the second line unchanged (that is, left is as: if (typeof oldValue === 'undefined' || field.val() !== e.effect.value) ). This seems logical to me - but I'm confused as to how it works for some people with the change to that second line added.

    I looked at the code in the conditional_fields.js downloaded file for the 7.x-3.x-dev version of the module, and that's the way it was in there (First line changed, but not the second) - so I thought I'd give it a shot, and sure enough it works!