Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
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.
Comment | File | Size | Author |
---|---|---|---|
#14 | After-patch-radio.png | 120.98 KB | kasliwal_harshit |
#12 | Screen Recording 2023-10-27 at 11.32.40 AM.mov | 4.26 MB | MukhtarM |
#11 | 3395689-11.patch | 801 bytes | MukhtarM |
#4 | warning-message.png | 41.28 KB | viren18febS |
#4 | conditionally-hidden-fields-inconsistently-required-fixes-3395689.patch | 844 bytes | viren18febS |
Issue fork webform-3395689
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:
- 3395689-conditionally-hidden-fields changes, plain diff MR !372
Comments
Comment #3
kasliwal_harshit CreditAttribution: kasliwal_harshit at Material for Drupal India Association commentedHi @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.
Comment #4
viren18febS CreditAttribution: viren18febS at Concinnity Media Technologies for Concinnity Media Technologies commentedHI @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.
Comment #5
viren18febS CreditAttribution: viren18febS at Concinnity Media Technologies for Concinnity Media Technologies commentedComment #7
sassafrass CreditAttribution: sassafrass commentedComment #8
sassafrass CreditAttribution: sassafrass commentedI 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.
Comment #11
MukhtarM CreditAttribution: MukhtarM as a volunteer and at Material for Drupal India Association commentedThe 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 thefieldset-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.Comment #12
MukhtarM CreditAttribution: MukhtarM as a volunteer and at Material for Drupal India Association commentedAttaching screen recording
Comment #13
viren18febS CreditAttribution: viren18febS at Concinnity Media Technologies for Concinnity Media Technologies commentedComment #14
kasliwal_harshit CreditAttribution: kasliwal_harshit at Material for Drupal India Association commentedI 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.
Comment #15
sassafrass CreditAttribution: sassafrass commentedI have applied the patch #11 , working as expected now the required(*) symbol in showing on the radio field . Thanks!
Comment #16
jrockowitz CreditAttribution: jrockowitz as a volunteer and at The Big Blue House commentedComment #18
Liam Morland