Problem/Motivation

Steps to reproduce

1. Create a webform with radios, checkbox, checkboxes elements
2. Create a required textfield or another (use this to generate error)
2. Go to webform settings and remove client-side validation
3. Submit test form submission with some checkboxes checked, radios selected
4. Note that the values submitted for radios and checkboxes are not rendered

Proposed resolution

Update preprocessing of checkboxes to use `#value` rather than `#default_value`.

Remaining tasks

User interface changes

API changes

Data model changes

CommentFileSizeAuthor
#17 image.png179.08 KBdanielgry

Issue fork civictheme-3495607

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

richardgaunt created an issue. See original summary.

dhruv.mittal’s picture

Assigned: Unassigned » dhruv.mittal

Working on it

richardgaunt’s picture

Hi @dhruv.mittal,

Pull requests for this project are done on this repository via GitHub: https://github.com/civictheme/monorepo-drupal

There are three parts to this solution:

Update the civictheme_preprocess_fieldset__form_element__civictheme_field__checkboxes and civictheme_preprocess_fieldset__form_element__civictheme_field__radios
In `civictheme_preprocess_fieldset__form_element__civictheme_field__checkboxes`:

We need to change this line:
https://github.com/civictheme/monorepo-drupal/blob/develop/web/themes/co...
And
https://github.com/civictheme/monorepo-drupal/blob/develop/web/themes/co...

to check for `#value` rather than `#default_value`

Update the checkbox preprocessing

We need to change the checkbox preprocessing at: https://github.com/civictheme/monorepo-drupal/blob/develop/web/themes/co... to something like this

 if ($element['#type'] === 'checkbox') {
    $variables['control'][0]['is_checked'] = $element['#value'] ?? FALSE;
    $variables['control'][0]['is_checked'] = (bool) $variables['control'][0]['is_checked'];
  }

Add some behat tests
We need to add some tests ensuring that in error forms retain their values for checkboxes and radios

dhruv.mittal’s picture

Assigned: dhruv.mittal » Unassigned
Status: Active » Needs review

HI @richardgaunt,
I have done the all the suggested changes.
But I don't know about behat tests, I would love to help if you guide me about them.

richardgaunt’s picture

@dhruv.mittal Could you create the PR from a forked https://github.com/civictheme/monorepo-drupal this way I can review and merge there. Changes from github get pushed up to this repository.

I can review and have behat tests added there.

dhruv.mittal’s picture

I have created the pr for the same please review
https://github.com/civictheme/monorepo-drupal/pull/1319

richardgaunt’s picture

  • e003a168 committed on 1.x
    Issue #3495607 by dhruv.mittal, richardgaunt: Checkbox and Radio Inputs...
dhruv.mittal’s picture

@richardgaunt thanks for merging the MR, could you please change the issue status to "FIXED".

fionamorrison23’s picture

@dhruv.mittal we will update the status after this work has been tested. Thanks for your contribution.

fionamorrison23’s picture

fionamorrison23’s picture

Assigned: Unassigned » danielgry

fionamorrison23’s picture

danielgry’s picture

Verified and tested on 1.x-dev

Testing Results:
1. Checkboxes and radio inputs retain their selected state after form validation errors
2. Inspected the checkbox input and confirmed the checked attribute is correctly present before data-drupal-selector

Screenshot:

danielgry’s picture

Issue summary: View changes
StatusFileSize
new179.08 KB

Adding screenshot as part of comment above:

danielgry’s picture

Issue summary: View changes
Status: Needs review » Reviewed & tested by the community
danielgry’s picture

Assigned: danielgry » richardgaunt
fionamorrison23’s picture

richardgaunt’s picture

Version: 1.9.0 » 1.10.0
Status: Reviewed & tested by the community » Fixed
fionamorrison23’s picture

Version: 1.10.0 » 1.9.0
fionamorrison23’s picture

Version: 1.9.0 » 1.10.0

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.