Checkboxes are not being handled correctly by conditional_fields/src/Plugin/conditional_fields/handler/OptionsButtons.php - tried in Druapl 8.3x and 8.4. Specifically:
protected function checkBoxesHandler($field, $field_info, $options) {
No longer works with the fields correctly as they are being rendered differently by Drupal 8.
An admin will get the following error messages when they try to work on forms:
"Notice: Undefined index: #return_value in Drupal\conditional_fields\Plugin\conditional_fields\handler\OptionsButtons->checkBoxesHandler() (line 107 of modules/contrib/conditional_fields/src/Plugin/conditional_fields/handler/OptionsButtons.php)."
This will not terminate form handling, however it will stop any conditional field settings from being applied, and will just show everything in the form as normal regardless of any conditional field settings applied.
Form fields do not have the right visibility metadata appended for example they have:
visible="[name=\u0022field_solution_type[]\u0022]"
instead of "[name=\u0022field_solution_type[]\u0022]":{"value":["24"]}}"
I am looking at a fix to this myself in the meantime for an urgent project and will get back with my findings, however you are probably likely to be able to produce a more stable patch.
Comment | File | Size | Author |
---|---|---|---|
#21 | broken-checkbox-handler-2926437-21.patch | 996 bytes | euk |
#18 | broken-checkbox-handler-2926437-18.patch | 863 bytes | darshanchoudhary |
#10 | broken-checkbox-handler-2926437-10.patch | 877 bytes | Spokje |
Issue fork conditional_fields-2926437
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
xiss23 CreditAttribution: xiss23 commentedComment #3
colanRelated to #2891276: checked, !checked don't work because states set on checkbox, radiobutton wrapper divs, not HTML input elements?
Comment #4
dpopdan CreditAttribution: dpopdan at PitechPlus for PitechPlus commentedA quick fix
Comment #5
colanMissing space after "=".
Comment #6
emerham CreditAttribution: emerham as a volunteer commentedUpdated patch with code standards fixed.
Comment #7
Jonah Fenn CreditAttribution: Jonah Fenn commented@dpopdan and @emerham, thanks for the patch. I've tested it out and it works like a charm.
Comment #8
colanComment #9
SocialNicheGuru CreditAttribution: SocialNicheGuru commentedComment #10
SpokjeRe-roll for latest
8.x-1.x-dev
and absence of patch in related issue (which fixes this problem at a more global scale).Comment #11
SpokjeTried to explain cause of (seemingly random) test failure on first test attempt in this issue: #3078778: Using RandomGeneratorTrait->randomStringas input for fields causes random test failures
Comment #12
cweldon CreditAttribution: cweldon as a volunteer commentedIt looks like this also impacts "OR" and "XOR" when the field allows multiple values (e.g. it uses checkboxes). I can work on a patch to fix this but I am not sure if it should be posted here or as a new issue. While it is similar I do not want to hold up this patch from making it into production. Once I receive some feedback on what method is preferred (adding a patch here or creating a new issue) I will move forward with submitting the patch.
Comment #13
waako CreditAttribution: waako at Annertech commentedComment #15
waako CreditAttribution: waako at Annertech commentedCreated MR with re-roll of patch in #10 for latest 4.x
Comment #16
Guido_SI'm just facing a similar issue with checkboxes in drupal 9 (up to date) using the 4.0.0 alpha release.
I'm setting a price field as the target field and want the price field only to show up if the checkbox is set.
So I configure "the target field is visible when the control field has the value" and no matter if I choose "insert value from widget" and check the checkbox or leave it unchecked or choose "all values (AND)" and set it to 1 on the form it's always the same result.
Both fields are shown if the checkbox is unchecked and the price field gets hidden, when I check the checkbox instead of having it the other way round.
The data-drupal-states attribute on the price field is always:
data-drupal-states="{"visible":{"[name=\u0022field_field_name[value]\u0022]":{"checked":false}}}"
Can't test if the last patch already fixes this too, because it doesn't apply to the 4.0.0 alpha version or if it is even a completely different issue.
Comment #17
bbombachiniTried the patch from the MR and it's still not working for me?
Core 9.3.6
Conditional fields 4.x-dev
Replicate:
- Create a list field and allow unlimited number of values.
- Display as checkboxes.
- Create 1 textfield for each option and create 2 conditions (make it visible and required for ex).
- On the dependency, set to use the widget value.
- On node edit form, try to select multiple options.
Expected result: dependent fields values are there because condition is met.
Result: If you click one checkbox it will show its dependent, if you check another one, not a single dependent field will show/work.
Comment #18
darshanchoudhary CreditAttribution: darshanchoudhary at TATA Consultancy Services commentedPer my observation the issue is due to str_replace replacing the entire field name. Created a new patch which should only replace the key of the dependent field.
Comment #19
SocialNicheGuru CreditAttribution: SocialNicheGuru commentedI am seeing the same as #17.
Patch in #18 does not work
Comment #20
euk CreditAttribution: euk at WebFirst, Inc. commentedHi all!
I am experiencing the same issue as in #17.
The patch seems to work for me, however, I think for best results only the value in the last bracket of the selector should be replaced:
[name="field_field_name[another_group][VALUE]"]
Patch attached
Comment #21
euk CreditAttribution: euk at WebFirst, Inc. commentedRe-rolling patch with fixed formatting...
Comment #22
euk CreditAttribution: euk at WebFirst, Inc. commentedUpdated issue title, as it is applicable to both 8.x and 9.x.
Comment #23
euk CreditAttribution: euk at WebFirst, Inc. commentedComment #24
jurgenhaasTested #21 successfully, it fixes this problem.
Comment #26
heddnThanks for your contributions.
Comment #27
heddn