Page MenuHomePhabricator

Add support for arrays to HTMLForm's hide-if and disable-if
Closed, ResolvedPublic

Description

Background: for T322209, I have an HTMLMultiSelectField, and an HTMLInfoField whose visibility should be toggled depending on whether certain options are selected in the multiselect. If the possible options for the multiselect are 1, 2, 3, 4, and 5, I want the info field to be hidden if none of 1, 2, and 3 are selected. Encoding this with the currently supported hide-if syntax is impossible for two reasons. First, only scalars can be used in comparisons, which means fields like HTMLMultiSelectField (whose value is an array) cannot be used in hide-if altogether. Secondarily, even if array values were supported, I could still only use equality checks. Hence, the hide-if conditions would be something like: x === [] OR x === [4] OR x === [5] OR x === [4,5], which is quite heavy. This can easily get out of hand depending on the number of options that control the hide-if.

Proposal: allow arrays to be used as values in hide-if/disable-if conditions. This could be limited to arrays of scalars for the time being. Then, add support for operations on said arrays. An in_array equivalent would perhaps be a good start, and still be simple enough. The conditions above would be rewritten as in_array( 4, x ) OR in_array( 5, x ). Support for array intersection would be even nicer, but I guess that's more niche, and therefore not necessary.

Event Timeline

Change #1194581 had a related patch set uploaded (by Mhorsey; author: Mhorsey):

[mediawiki/extensions/CampaignEvents@master] Disable collaborative contributions if prerequisites are not met

https://gerrit.wikimedia.org/r/1194581

Change #1194250 had a related patch set uploaded (by Mhorsey; author: Mhorsey):

[mediawiki/core@master] Allow HTMLForm hide-if and disable-if to read values from multiselect fields Add new "IN" operator to handle fields with array values

https://gerrit.wikimedia.org/r/1194250

Change #1194250 merged by jenkins-bot:

[mediawiki/core@master] Allow HTMLForm hide-if and disable-if to read values from multiselect fields

https://gerrit.wikimedia.org/r/1194250

This will be testable together with T406073, where it's used to check that at least one of the selected event types allows tracking contributions.

vaughnwalters subscribed.

This will be testable together with T406073, where it's used to check that at least one of the selected event types allows tracking contributions.

Any of the selected event types that are required to allow tracking contributions (editing event, media upload event, backlog drive, contest) do correctly allow tracking contributions, and other event types that are required to not allow tracking contributions correctly do not allow tracking contributions. Sending to product sign off.

Screen Recording 2025-10-24 at 5.15.19 PM.gif (2,592×1,808 px, 1 MB)