Problem
Within the javascript method updateFieldValue the value of the hidden text field is set by jquery's val() method.
Unfortunately no change event is dispatched by this method, so the States API won't recognize the changed value.
Probably #2144869: Simple hierarchical select and conditional field are not working together? has something to do with that too, but since they strongly focus on the Conditional Fields module, I opened this new issue.
Solution
Trigger the change event manually.
Steps to reproduce
1.) Create a node type using a text field and a taxonomy field using shs.
2.) Add the following state to the text field:
array(
'#states' => array(
'enabled' => array(
'css_selector_matching_the_hidden_select_field' => array('value' => '1'),
),
),
);
3.) Now the text field should be disabled unless the taxonomy term #1 is selected in the shs field. But it stays disabled, even if the term #1 is selected.
| Comment | File | Size | Author |
|---|---|---|---|
| #9 | shs.js.txt | 20.73 KB | Mirkozzo |
| #6 | shs-dispatch_change_event-2264795-6.patch | 194 bytes | l0ke |
| #6 | interdiff-2-6.txt | 269 bytes | l0ke |
Comments
Comment #1
Tobias Xy commentedCreated a patch.
Comment #2
arosboro commentedPatch didn't apply cleanly for me. Re-rolled it against the latest dev branch, and it works with the states api as described.
Comment #3
arosboro commentedThe patch I submitted is identical to the author's. What I didn't realize is that I was applying it to the non dev release of this module. In this case you need to take care that the change event gets added to the correct javascript function.
Comment #4
simeonkesmev commentedWorks for me.
Comment #5
sgdev commentedI'd appreciate any feedback on the patch I've created that extends what's included in this patch: updateFieldValue doesn't dispatch an accessible change event
Thanks.
Comment #6
l0keChange event triggered only when we going deeper in hierarchy. This means if for example we had some value selected and now we want to select "_none" change event won't be triggered.
I moved trigger out of conditional state to call it in all cases.
Comment #7
Mirkozzo commentedI did not understand what patches to apply on which version, i tried to add the line n°542 to shs.js 7.x-1.6 and 7.x-1.6+56-dev
but it had no effect.
I urgently have #states working with shs module, or other system to dynamically use the terms of taxonomy from shs widget
Comment #8
l0kePatch made for dev version, and worked fine for me.
Can you please provide code listing of form, so I can take a detailed look.
Comment #9
Mirkozzo commentedI attached my shs.js (7.x-1.6+56-dev) modified
but it had no effect.
If i use default taxonomy drupal widget -> work
If i use shs widget -> not work (field_my_field_text is always shown)
That is highly urgent for me :/
Comment #10
sgdev commented@Mirkozzo, I understand you're trying to get things to work, but we're all dealing with highly urgent problems. What you're requesting is a support issue, not a problem with the patch. I'd like to make two suggestions:
1) Create a new ticket as a support request and see if others can provide some assistance with your issue.
2) Spend some time reviewing the module APIs in the
shs.api.phpfile. This will provide additional details on how the widget can be hooked and altered to achieve your goals.Comment #11
Mirkozzo commentedTnx for help me
I found the error
[...]
':input[name="field_my_taxonomy_field[und][0][tid]"]' => array('value' => 'tid_number'),
[...]
I have modify shs.js of stable release 1.6....work fine
Comment #12
stborchertThis has been fixed recently.
Comment #13
sgdev commented@stBorchert, we tested this extensively, and found that the change trigger needed to be one level higher in the nested conditionals. If it isn't moved up, there are some cases where it doesn't work.
I've created an updated patch (https://www.drupal.org/node/2499279#comment-10917127) that includes a feature to allow an accessible change event. I'd appreciate if you can review it. Thanks.