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.

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

legolasbo created an issue. See original summary.

legolasbo’s picture

legolasbo’s picture

legolasbo’s picture

Parent issue: » #2633094: 8.x-1.0 Roadmap

  • legolasbo committed d1bd0d5 on
    Issue #2635664: Make the hide/show of the other field work
    
    Squashed...
legolasbo’s picture

Status: Active » Postponed

Implemented #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.

legolasbo’s picture

This also needs to be backported to 7.x. See #2488694: Refactor to make use of form states API

  • legolasbo committed d1bd0d5 on 8.x-1.x
    Issue #2635664: Make the hide/show of the other field work
    
    Squashed...
legolasbo’s picture

Version: 8.x-3.x-dev » 8.x-1.x-dev
legolasbo’s picture

Component: CCK / Field API widget » Field widget (non-specific or listed)
StatusFileSize
new3.52 KB

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

starlight-sparkle’s picture

Component: Field widget (non-specific or listed) » Code

This issue is now postponed until #1149078: States API doesn't work with multiple select fields lands.

That core patch has landed last year, should this issue be marked active?

ivnish’s picture

Version: 8.x-1.x-dev » 4.x-dev
Status: Postponed » Active
Issue tags: -Needs backport to D7

Is it relevant?

starlight-sparkle’s picture

Implemented #states for all but the multi value select element for which I added a custom JS script.

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

Uncaught TypeError: $(...).once is not a function
    at Object.attach (MultipleSelectStatesHack.js:33:58)

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.

ivnish’s picture

JS code was fixed in dev version

ivnish’s picture

Status: Active » Closed (won't fix)

Already fixed, I'll add credit records

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.

starlight-sparkle’s picture

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

ivnish’s picture

Category: Task » Bug report
Status: Closed (won't fix) » Active

I understand how it works now. States work for Entity reference field, but doesn't work for List field