Incorrect validation submitting webform with mandatory checkboxes

Created on 24 April 2023, over 1 year ago
Updated 7 May 2023, over 1 year ago

1.0 Problem/Motivation

I have a Webform which is creating/updating CiviCRM Contacts. One field contains four checkboxes and is marked Mandatory.

If the user selects an existing record in order to update it, at least one of the checkboxes will already have been filled in. If they then update some other field and submit the form it gives a validation error asking that the checkbox field be filled in, even though one box is ticked already.

In particular this occurs on a CiviCRM 'Tags' or 'Groups' field, it does not occur on e.g. 'Privacy Preferences' or text fields such as Name. If I remove the 'Multiple' option from the Tags or Groups field, so that it becomes radio buttons, then it does not throw the error.

There is a workaround, to untick and re-tick the box, after which it is accepted, but this is not necessarily obvious to the user.

2.0 Detailed steps to reproduce (embed screenshots)

See attached file containing export of a simplified form showing the same behaviour. Select an existing Contact, update it to select a Tag and suitable Group. Select the same contact, change the name and Submit - give a validation error saying Please Complete This Field.

🐛 Bug report
Status

Needs review

Version

6.2

Component

Code

Created by

🇬🇧United Kingdom maynardsmith

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

  • Issue created by @maynardsmith
  • 🇮🇳India jitendrapurohit

    Looks like its working fine for me. @maynardsmith Can you please add some more information? Eg Drupal & Webform module version?

    This is what I did and the webform submitted fine without any validation issue -

    - Imported your attached webform.
    - Opened the webform and selected a contact => Tag, Group and other information loaded automatically (See screeenshot).
    - I haven't touched any other field and simply clicked on submit.
    - The webform was submitted.

  • 🇬🇧United Kingdom maynardsmith

    Thank you @jitendrapurohit

    You have uncovered a subtlety that I had missed. The problem does not occur if the first option in the Tags field is checked (with or without others). It does occur of one of the others is checked, but not the first one. My statement above that it does not occur on Privacy Preferences is wrong - I must have only tested that field with the first one checked.

    I should have included the version details before. This is on: Drupal 9.5.8; CiviCRM 5.60.0; Webform 6.1.4; Webform CiviCRM Integration 6.2.4.

  • Status changed to Needs review over 1 year ago
  • 🇮🇳India jitendrapurohit

    Ah yes @maynardsmith. I was able to replicate it now for other checkbox elements.

    Looks like webform assigns required=required attribute to the first checkbox element. Triggering a change event on the 3rd checkbox does not toggle the required attribute from the first option. I've raised a PR to fix - https://github.com/colemanw/webform_civicrm/pull/875

    Can you please apply the patch and review it?

    Thanks.

  • 🇬🇧United Kingdom maynardsmith

    Thank you. Works for me (versions as above).

    Tony

Production build 0.71.5 2024