Set field to be required not working with checkbox

Created on 28 August 2020, almost 4 years ago
Updated 6 March 2024, 4 months ago

Problem

Made fields visible and required when a checkbox field is checked.

Steps to reproduce

Created a field of type checkbox and an image field. The image field is configured to be visible when checkbox is checked. and also, it should be required in that case. But the field slides down and upon checking and unchecking the checkbox. But the required functionality is not working.

🐛 Bug report
Status

Postponed: needs info

Version

4.0

Component

Code

Created by

🇮🇳India er.garg.karan Chandigarh

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

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

  • 🇺🇸United States aitala

    The patch did not work for me either -

    I have a set of four checkboxes that are supposed to control if a link field (url and text) need to be filled out. With all the boxes unchecked, all the link widgets are visible. When I start checking boxes the results are unpredictable.

    What did work was changing the controlling field from checkboxes to a pulldown.

    Thx
    Eric

  • Status changed to Needs work about 1 year ago
  • 🇺🇸United States sim_1

    I'm having the same issue. It was working for me before. Now with alpha2 and drupal 9.5 it is no longer working.

  • 🇮🇳India saurabh-2k17

    Hi, I am facing the same issue and came across this thread. I see there is also a dependency by Drupal core 🐛 HTML5 validation is preventing form submit and not fully accessible Needs work

    I applied #3 patch from here along with other patch from the Drupal core issue, but this is not working.
    Furthermore, I am also on Drupal core 9.5 and alpha2 version of module. I am curious to know what was the last Drupal core version for which this was working?

  • 🇮🇳India saurabh-2k17

    I am attaching a working patch here.

  • 🇮🇳India saurabh-2k17

    Apologies for the wrong naming

  • Open in Jenkins → Open on Drupal.org →
    Core: 9.5.x + Environment: PHP 8.0 & MySQL 5.7
    last update about 1 year ago
    130 pass
  • Status changed to Needs review about 1 year ago
  • 🇺🇸United States jmester13

    @saurabh-2j17 I've tried your patch and the core patch and am not seeing a solution, but maybe because my setup is slightly different.

    I have a required radio button.
    When an option is selected, A required textbox should display.
    When the option is not selected, the required textbox is hidden but does not allow the form to be submitted.

    Also seeing this same behave for a checkbox which when selected should show a required address field.

    Still researching and trying to find a solution but wanted to post here and follow.

    Thanks!

  • 🇺🇸United States jmester13

    Alrighty so update here for anyone else who runs into this issue I hope it helps.

    I did not use these patches in the end it comes down to logic.

    Do not set required on the field itself. Use the conditional logic to set required!

    For example
    (checkbox) Yes / No
    Do you like Pizza?
    If Yes, Show text field
    If Yes, Make text field required.

    For Address fields, I'm still working on a resolution, looking like some type of custom JS.

  • 🇮🇳India Shani Maurya Mumbai

    Patch in #3 worked for me only. Thank You!

  • 🇬🇧United Kingdom Problue Solutions Northern Ireland

    On Drupal 10.2 with Claro or Gin themes, when the checkbox is first clicked nothing happens, when it is clicked a second time the dependent field appears, and with each subsequent click the field disappears and appears correctly. It is only the very first click that does not work.

  • Status changed to Postponed: needs info 4 months ago
  • 🇩🇪Germany diqidoq Berlin | Hamburg | New York | London | Paris

    Thanks for the report and the efforts in here +1

    Removed tag. Before adding tags read the issue tag guidelines . Do NOT use tags for adding random keywords or duplicating any other fields. Separate terms with a comma, not a space.

    At the moment maintainers cannot reproduce this issue, tested with default Drupal 10.2 core and Claro setup (watch screen-cast). Please provide more reports and a screen-cast showing setup, themes and modules installed, so that we can make sure that this is really caused by CF.

    Note: It makes a difference if the image field was set as required by default or not before, or if the checkbox has been checked already before or not for testing. To be able to turn off the required mode is already an issue because this is not working at the moment for good reasons. Therefor please follow: 🐛 URL validation of link field doesn't work Fixed or 📌 Support field turning hidden by condition to loose its required status Needs work .

Production build 0.69.0 2024