Problem/Motivation
Simple hierarchical select and conditional field are not working together. Can I use Simple hierarchical select to hide/show a field?
Steps to Reproduce
- Enable SHS and Conditional Fields
- Create a taxonomy called 'Property Type' with 2 levels:
- Printer
- Local
- Multifunction
- Network
- Laptop
- Notebook
- Tablet
- Backup
- Tape Backup
- Tape Library
- Printer
- Note the Term IDs for: Printer, Color, Multifunction, Network
- Navigate to: Structure > Content Types > Basic page > manage fields
- Add a term reference field called 'Property Type' that uses the widget type = Simple Hierarchical Select. Use the 'Property Type' vocabulary. Defaults for this field should be fine.
- Create a boolean field called 'Color Printer?'
- Click the 'Manage Dependencies' tab
- Add a new dependency:
- Dependent = 'Color Printer?'
- Dependee = 'Property Type'
- The dependent field is [visible] when the dependee [has value...]
- Click 'Add Dependency'
- Change the dropdown value of 'Values input mode' to 'Any of these values (OR)...'
- For 'Set of values:' enter in the Term IDs (see #3), one ID per line
- Click 'Save Settings'
- Navigate to: Content > Add content > Basic page
- On the form, verify that the 'Color Printer?' field is hidden.
- Change Property Type to 'Printer' or one of its children. Verify that 'Color Printer?' appears.
| Comment | File | Size | Author |
|---|---|---|---|
| #29 | shs-field_conditions_and_shs-2144869-29.patch | 609 bytes | vtcore |
| #18 | shs-field_conditions_and_shs-2144869-18.patch | 1.33 KB | loparev |
| #13 | 2144869-13-shs_conditional_fields.patch | 934 bytes | marcvangend |
| #7 | shs-work-with-conditional-fields-2144869-7.patch | 226 bytes | adammitchell |
Comments
Comment #1
stborchertAdded a states handler for conditional fields to SHS.
Comment #3
baba310 commentedThanks for your reply. I have again tried it with
Drupal: 7.24
conditional field: 7.x-3.0-alpha1
SHS: 7.x-1.x-dev (18th Dec 2013)
but it is still not working. However, I have noticed that handler was added in shs.module file. Unable to figure out the issue. Please if anyone can help me in this issue.
thanking you again.
Comment #4
adammitchell commentedI managed to get this working by placing the code below inside the updateFieldValue function in shs.js:
$field_orig.trigger('change');I also had to manually adjust the dependee selector inside the "Advanced edit context settings" fieldset in the conditional field module, because this was being saved incorrectly.
Comment #5
milos.kroulik commentedI tested it with latest dev versions of both modules and got following errors:
So I think this should be marked as active.
Comment #6
frommarcq commentedHi Adam,
Same trouble, between SHS and conditional fields...
In #4, you explained :
Could you give me more details (where to place the
in shs.js) ?
What did you mean when you explained in "adjust the dependee selector" ?
Thanks in advance !
Regards.
From
Comment #7
adammitchell commentedHi Frommarcq
I have attached a patch for altering the js file.
With regards to changing the conditional fields selector. Go into manage dependencies and navigate to the Advanced edit context settings fieldset. I have added a screenshot of the selector that I used to make this work.
Let me know if you have any difficulties and I will help you out.
Adam
Comment #8
doppel commentedStill not working on mine.
Comment #9
frommarcq commentedHi Adam,
Thank you for this patch. I think you use the "dev" version. So I installed it too. I followed your instructions, without any change :
the dependant is always displayed, even if the dependee ("field_rubrique") is different of "2" (or empty).
If I change the widget to "select list" instead of "shs" (and remove '[name="field_rubrique[%lang][%key][%tid]"]' from "Custom jQuery selector for dependee" field, the dependant is only displayed if the dependee is equal to "2".
Here's the field dependency's screenshot (maybe it is wrong ?)
Regards.
From
Comment #10
frommarcq commentedComment #11
summit commentedHi,
Anyone have SHS working with Conditional Fields normally?
Thanks for sharing how to than.
greetings, Martijn
Comment #12
smallgab commentedHi!
I have the very same probleme here. The interesting thing about my version is that I'm not using any SHS widget type either in the dependent or the dependee fields. In my content type, I have a term reference field, which is using SHS as widget, and I have two other fields, one is a simple Logical field with Yes and No options and the other one is an Entity Reference which has two values and is only active when the Logical field is set to Yes.
I'm not an experienced coder, but I guess SHS has something to do with my Entity Reference field because I could select SHS as a widget type there (but I did not... It is an Autocomplete textbox and it refers other ones from the same content type it's in). Or maybe when I'm trying to add a new one of that content type, SHS and Conditional Fields detect each other and just droping the error messages mentioned in the fifth comment.
I'm fairly new to Drupal, and I don't know if it's the key to solve this issue, but I hope there is someone out there with a solution. And I hope it helps a bit.
Comment #13
marcvangendI had the same problem as #12. Error logs showed a fatal error triggered at line 195 of shs.module:
I managed to fix / work around the error using the patch attached, but to be honest, I don't have a clue what the shs_conditional_fields_states_handler_shs() function is supposed to do and I cannot guarantee that it will solve anyone's problem except my own :-)
Comment #14
smallgab commentedThanks marcvangend!
It solved my problem partially. I don't get the 3rd notice described in comment #5 but the other two is still shown. I have no functional problems though. Definitely one step closer. :)
Comment #15
marcvangendThanks for the feedback, smallgab. You're probably right, in my case I only got the 3rd notice so I didn't fix the other two.
Comment #16
presleyd commentedThe issue in #13 came up for me recently on a node form for a content type that did not have a term reference field much less a SHS widget. I have no idea why it was an issue there but I do use conditional fields heavily on this content type so maybe its related. The patch in #13 fixed the issue. I did not reroll it since it was just 2 new lines of code but I can if needed.
Comment #17
Maximus8 commentedI have the same/similar problem...im using profile2 with 2 different profiles and added a shs-widget in one profile to choose the state/land/region...the funny thing: the error message also appears when editing the second profile, where no shs-widget is used. I do not use the conditions to hide or show the shs-widget but the errors appear in the profile2-edit-form. For every condition set i get 2 errors:
#13 resolved the third error message, but the other two still remain...is there anything in progress or any idea where this bug may be fixed?
Comment #18
loparev commentedHi all.
I tried to combine #7, #13 patches with my solution of
Notice: Array to string conversion in conditional_fields_form_after_build() (line 547 of /var/www/drupal/sites/all/modules/contrib/conditional_fields/conditional_fields.module).error when shs and conditional fields are both enabled on the site (notice occurs on node add page). I use conditional fields version 7.x-3.0-alpha1 and shs version 7.x-1.6+56-dev. And this patch resolves notices and warnings.Comment #19
tobiberlinI use the latest dev version which is just missing this part of the patch:
Although I added this javascript part the field which should be just visible if a specific value in my shs field is chosen is visible all the time. The other patches seem to be merged to current dev version?!
Comment #20
tobiberlinThe array to string conversion notice seem to be a known issue with array comparing PHP function (https://bugs.php.net/bug.php?id=60198)... when an shs field is used as dependee the arrays checked in
(conditional_fields.module, line 547)
have a nested array instead of a simple key/ value pair. This leads to this notice.
Comment #21
loparev commentedyep. that's why there is
in this patch.
I wanted to resolve notices and warning when shs and conditional fields are enabled. And at least warnings and norices are fixed.
Comment #22
cmanalansan commentedAdded 'Steps to Reproduce' section for easier review.
Comment #23
mqannehPatch #18 worked perfect for me
Comment #25
stborchertThis is not correct, as the dependee form field is nested multiple times.
Debug into
conditional_fields_form_after_build()and have a look onforeach ($state_handlers as $handler => $handler_conditions) { ... }. With this modification, the state handler defined in SHS is never called.The PHP notice is caused by
array_intersect_assoc()which does not work well with multi-dimensional arrays. See http://stackoverflow.com/q/19965438.Comment #28
stborchertAdded a (somehow hacky) fix so SHS should work with Conditional fields. To get rid of the PHP notice you will need to patch Conditional fields. See #2682015: Array to string conversion in conditional_fields_form_after_build().
Comment #29
vtcore commentedFor me the latest dev version still didn't work properly. It seems that the old state selector remains in the array and needs to be unset().
See the attached patch.
Comment #30
mjgruta commentedPatch #29 works for me on the latest dev version.
Comment #32
TheDukeofURL commentedThis only works if you're using the deepest level term AND setting your dependency value via the "insert value from widget" rather than the "set of values" options.
If you want the condition to be based on the highest level parent(which would have to be done via the "any of these values(OR)" setting) so that the conditional field will show for ANY of the children of a particular tree, it will not work.
It will also fail to work via "insert value from widget" if you are not forcing deepest level selection but the dependency term exists in the first level of the tree and the user goes deeper.
Comment #33
elgandoz commentedSame exact issue happens for the 8.x version
Comment #34
bloomt commentedIs there a solution for drupal 8 version?
Comment #35
summit commented+1 for Drupal 8 version!
Comment #36
tregismoreira commentedI was able to make it work on Drupal 8 by setting the Values input mode as Set of values.
Comment #37
summit commentedHi, Great this is also working for Drupal 8! But probably no maintainer anymore...
greetings,