- Issue created by @merilainen
- ๐ซ๐ฎFinland merilainen
Here is a patch which will add support for the checked trigger. It works with both "visible" and "required" states.
This approach alters the schema properties and uses the if & then properties instead of using the "dependencies" keyword which is not supported by the latest JSON Schema if I understood correctly. - Status changed to Needs review
7 months ago 12:31pm 4 April 2024 - ๐ซ๐ฎFinland merilainen
Here is an improved version of the patch which also works with the "empty" trigger, at least to a certain degree.
Having the patch from โจ Default value not available in response Needs review helps in some cases. - ๐ซ๐ฎFinland merilainen
Yet slightly improved version which uses if-not-then properties instead of if-else. Seems to work better without default values in the schema too.
- ๐ซ๐ฎFinland merilainen
This iteration of the patch adds support for multiple triggers per state and moves the handling of the "filled" trigger from the
prepareDependencySchema()
to thealterSchemaProperties()
so that multiple "filled" triggers can be used per state.
ThewebformElementStatesAfterBuild()
has not been touched yet because I could not get it working on my local.It starts to feel like major refactoring could be in place, but there is still a lot of handling of the "Value is" trigger which I don't want to touch and might not need to be changed in the end.
- ๐ซ๐ฎFinland merilainen
Fix for "Notice: Only variable references should be returned by reference".
- Status changed to Needs work
7 months ago 6:59am 11 April 2024 - ๐ซ๐ฎFinland merilainen
This patch takes more drastic approach and removed the use of the non-draft dependencies keyword completely. "Values is" trigger is also handled in the if-then-else structure which seems to work nicely too.
It also changes the getDependencyKey() function so that it will not throw an exception, because it seems to break Webform UI if there is a container element anywhere in a webform. This part needs still more work, because currently it allows to add any element into a condition and many of them do not work correctly. - ๐ซ๐ฎFinland merilainen
This version will replace most of the conditions from if-then to if-not-else because the if-then else logic seems to require some default values in the schema for the elements. The if-not-else seems to work better and makes validation easier when there are no default values in the elements.
- Status changed to Needs review
6 months ago 11:16am 8 May 2024 - ๐ซ๐ฎFinland merilainen
This will just affect the Drupal UI so that only "oneOf" operator can be selected. The if-then-else (with "not" in the mix) doesn't seem to work easily with "allOf" or anyOf" operators.
Marking as "Needs review" because it would be nice to know if this approach makes sense. - ๐ซ๐ฎFinland merilainen
I had incorrect operator machine name, changed "one" to "xor". Also setting default value didn't work, so I removed that.
- ๐ซ๐ฎFinland merilainen
And apparently that broke the rendering, so I will just fake the selection "All" as "One" which works with the if-then-else logic.
- Status changed to Needs work
6 months ago 2:33pm 31 May 2024 - ๐บ๐ธUnited States kurttrowbridge
I think this is related to this issue and its patch, but apologies if it's unrelated. I added this patch because I was having issues with a field that has multiple visibility conditions (e.g. Field 2 is visible if the answer to Field 1 was Option A or Option B). With the patch installed, that results in an error on line 64 (
$trigger = key($triggerValue);
) because of the or condition: the$triggers
array that is looped through includes a non-array value,or
, between the actual visibility conditions, so there's no array key to assign to the$trigger
variable. I've attached a screenshot of what the$triggers
variable contains. Not sure if it's as straightforward as confirming that$triggerValue
is an array before continuingโI may try it and report backโor if that would cause an issue with the or condition not taking effect.(Possibly of note: I have the patch installed atop version 2.0.10, not 2.0.x-dev, since the dev version is behind it and doesn't support version 6 of Webform.)