[MGNLFORM-297] Validation error on 2 forms with mandatory checkboxes - multiple selection enabled Created: 20/Nov/17  Updated: 23/Aug/22

Status: Open
Project: Magnolia Form Module
Component/s: validation
Affects Version/s: 2.4
Fix Version/s: None

Type: Bug Priority: Neutral
Reporter: Heike Franosch Assignee: Unassigned
Resolution: Unresolved Votes: 1
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Template:
Acceptance criteria:
Empty
Task DoD:
[ ]* Doc/release notes changes? Comment present?
[ ]* Downstream builds green?
[ ]* Solution information and context easily available?
[ ]* Tests
[ ]* FixVersion filled and not yet released
[ ]  Architecture Decision Record (ADR)
Bug DoR:
[ ]* Steps to reproduce, expected, and actual results filled
[ ]* Affected version filled
Date of First Response:
Team: AuthorX

 Description   

Steps to reproduce:

  • Put 2 forms on a page each with mandatory e.g. checkboxes and multi selection enabeld
  • Fill out fist form (check at least one checkbox) and submit
    Failure:
    Error message "Please check at least one of the checkboxes" is shown.

That's because the javascript for the second checkboxes also validates the
mandatory requirement.



 Comments   
Comment by Sahin Guener [ 01/Nov/18 ]

Here is a working fix (File: form/components/formSelection.ftl):

<script type="text/javascript">
    var checkboxes = document.getElementsByName("${content.controlName}");
    var element = checkboxes[0].form;
    var valid = false;
    element.onsubmit = function () {
        var checkboxes = document.getElementsByName("${content.controlName}"); //<--- The line prevents that only the checkboxes from the last form are validated.
        for (var i = 0; i < checkboxes.length; i++) {
            if (checkboxes[i].checked) {
                valid = true;
                break;
            }
        }
        if (valid) {
            document.getElementById("checkbox-error").style.display = "none";
        } else {
            document.getElementById("checkbox-error").style.display = "block";
        }
        return valid;
    }
</script>

 

Please provide a fix asap. This issue was created 1 year ago! Until then, we will overwrite the file ourselves.

 

Generated at Mon Feb 12 05:38:50 CET 2024 using Jira 9.4.2#940002-sha1:46d1a51de284217efdcb32434eab47a99af2938b.