Problem/Motivation
The checkboxes element fails on 2+ selections because of a submission-model mismatch between the NYSDS web component and Drupal's checkboxes element:
The NYSDS nys-checkboxgroup is a formAssociated web component. By design it collects all checked child values and submits them as one comma-joined string via ElementInternals.setFormValue(values.join(", ")), adopting the last-changed child's name. Meanwhile Drupal's checkboxes element expects separate array entries (checkboxes[Parent]=Parent, …). Core's Checkboxes::valueCallback() turns the CSV into a single bogus array key, and FormValidator rejects it. The child checkboxes stay silent when grouped (groupExist === true), so the group is the sole submitter.
Possible approaches:
- Template-only: remove the wrapper so each submits its own array entry and manually re-create the checkboxgroup fieldset manually with nys-label and nys-errormessage included explicitly
- JS / editing the group: behavior is in the compiled upstream package; value: null is overridden at runtime. Need to request a special prop from NYSDS team.
- PHP #value_callback override in a module.
Issue fork nys_ds-3593900
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
loopy1492 commentedComment #3
loopy1492 commentedComment #4
loopy1492 commentedPossible solution:
Comment #5
loopy1492 commentedAdding the value: element['#value'], to the component seems to help it pass validation with Drupal, but when the form returns back with edits, the javascript seems upset that a value has been set.
Comment #6
loopy1492 commentedThe NYSDS adds the "name" of the selected checkbox to the fieldset every time it is clicked. In the NYSDS example, it is expected that a checkbox group will all have the same "name". In Drupal, this is not the case. It does appear that the NYSDS uses the proper method. We will have to try using the fieldset name in the indivudal checkboxes. Hopefully that does not cause data saving issues.
Comment #8
loopy1492 commentedThe merge request includes code to "patch" the existing checkboxgroup component in lit.
Comment #10
loopy1492 commentedComment #12
loopy1492 commented