It was my hope to make the hide/show of the 'other' field fully dependant on Form API's #states. This is unfortunately prevented by #1149078: States API doesn't work with multiple select fields.
Let's explore how far we can get with the form states API and which hack is needed until #1149078: States API doesn't work with multiple select fields lands.
| Comment | File | Size | Author |
|---|---|---|---|
| #10 | make_the_hide_show_of-2635664-10.patch | 3.52 KB | legolasbo |
Issue fork select_or_other-2635664
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
Comment #2
legolasboComment #3
legolasboComment #4
legolasboComment #6
legolasboImplemented #states for all but the multi value select element for which I added a custom JS script.
This issue is now postponed until #1149078: States API doesn't work with multiple select fields lands.
Comment #7
legolasboThis also needs to be backported to 7.x. See #2488694: Refactor to make use of form states API
Comment #9
legolasboComment #10
legolasboI've reviewed #1149078: States API doesn't work with multiple select fields and marked it RTBC. When that issue lands we can remove the javascript hack. Attached patch can be used to do so.
Comment #11
starlight-sparkleThat core patch has landed last year, should this issue be marked active?
Comment #12
ivnishIs it relevant?
Comment #13
starlight-sparkleThe JS hack shipped with this module for multi-value select elements is now broken in Drupal 10+, because of the use of
jQuery.once, which was deprecated in Drupal 9.3 and removed in 10.0.This error will appear in JS console, and the "other" field will not hide properly.
I could not get patch #10 to apply, but I have manually replicated its changes and it seems to resolve this issue.
If desired, I can convert the patch into an MR.
Comment #15
ivnishJS code was fixed in dev version
Comment #16
ivnishAlready fixed, I'll add credit records
Comment #18
starlight-sparkleThe intention of the previous maintainer was that the JS was always intended to be a temporary fix. I concur that the JS may still be needed today because this module still supports Drupal 10.1, which still requires the hack. However, the expectation is that it will likely break again in another year or two as it isn't making use of stable public interfaces. So if this needs to be marked not-active, I would suggest it goes back to postponed rather than closed.
Comment #19
ivnishI understand how it works now. States work for Entity reference field, but doesn't work for List field