Problem/Motivation

When adding two fields, one a Text field and one Radio buttons, where both are required and both are conditionally visible based on another field being checked, when I check the box, the Text field shows as Required and the Radio buttons do not. I've tried several themes and they all show the same result.

Steps to reproduce

I've attached an example form that exhibits this behavior and a screenshot of what I see.

Issue fork webform-3395689

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:

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

sassafrass created an issue. See original summary.

viren18febS made their first commit to this issue’s fork.

kasliwal_harshit’s picture

FileSize
109.89 KB
92.81 KB

Hi @sassafrass i tried to reproduce the issue with specified Webform version and D10, i can reproduce the same issue after checking the checkbox the radio button is not showing as required , but if we try to submit the form without selecting the value if the radio-box, we will get an error that please select a value .
Therefore i think the radio field is still required and working fine from backend logic. it is just not showing the required symbol(*) over the radio button , so it's more related of css / js issue and we can update the Title and description accordingly.
Moreover you can confirm the same over it.

Adding the screenshot for the reference.

viren18febS’s picture

HI @sassafrass

We get an warning message on webform, when we try to apply the visibility condition on radio field (as per issue description).

which is related to removing the required state from current form element.

If we hide the element based on conditions, then it will be change from required to optional for prevent the form submission error.

Attached screenshot of warning.

I have added a patch for above issue but not generated the MR, you can use the patch as per your need.

viren18febS’s picture

Status: Active » Needs review

Status: Needs review » Needs work

The last submitted patch, 4: conditionally-hidden-fields-inconsistently-required-fixes-3395689.patch, failed testing. View results
- codesniffer_fixes.patch Interdiff of automated coding standards fixes only.

sassafrass’s picture

Title: Conditionally hidden fields inconsistently required » Conditionally hidden fields inconsistently show required*
sassafrass’s picture

I agree that this is functioning as expected and it's just the asterisk that is not displaying. I've changed the issue title to reflect that. The asterisk does display as expected for field types other than radio buttons so I think it's specific to that field type. That being said, this patch un-does important functionality in that it removes the required functionality from hidden fields that are required, if they remain hidden (not used) when the form is submitted. I don't think we want to remove that functionality. We just want the asterisk to display on the radio buttons like it does for the other fields.

MukhtarM’s picture

The required class needed to be added to the fieldset-legend > span > label, Then only it displaying the asterisk. It's not displaying it when added to the fieldset-legend. Not sure about the previous follow ups on this, but the patch works well for me in local. Any other work around or more performatic way is welcome. Thanks.

MukhtarM’s picture

Attaching screen recording

viren18febS’s picture

Status: Needs work » Needs review
kasliwal_harshit’s picture

FileSize
120.98 KB

I have applied the patch #11 , working as expected now the required(*) symbol in showing on the radio field . Attaching the screenshot for the same we can move this to RTBC+1, Thanks.

sassafrass’s picture

I have applied the patch #11 , working as expected now the required(*) symbol in showing on the radio field . Thanks!

jrockowitz’s picture

Status: Needs review » Reviewed & tested by the community

Liam Morland’s picture

Version: 6.2.0-rc2 » 6.2.x-dev
Status: Reviewed & tested by the community » Fixed

Status: Fixed » Closed (fixed)

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