From d61d69cc2221f2b58acbe171b8a4fe900cb6b590 Mon Sep 17 00:00:00 2001 From: Emmi Takkinen Date: Fri, 15 Sep 2023 11:19:35 +0300 Subject: [PATCH] Bug 34671: Show error message if fieldset has invalid input If fieldset is collapsed and it contains required fields patron can be saved without filling these fields. This patch adds rule ignore as "" in form validation and displayes error message in fieldsets containing missing required inputs. To test: 1. Make sure you have "Main address" fields set as mandatory with BorrowerMandatoryField syspref (address, city, zipcode) 2. Add new patron, fill in some info, but leave "Main address" fields empty. 3. Attempt to save. => "This field is mandatory" should be displayed next to the address fields. 4. Collapse "Main address" fieldset. 5. Attempt to save again. => Patron is saved successfully without address information. 6. Apply this patch. 7. Edit patron and attempt to save again with "Main address" fieldset collapsed. => Error message "There are some required fields missing from this field set. Please fill them." should be displayed and patron isn't saved. 8. Fill missing fields, attempt to save. => Saving should now be successfull. Sponsored-by: Koha-Suomi Oy --- .../prog/en/includes/validator-strings.inc | 1 + koha-tmpl/intranet-tmpl/prog/js/members.js | 19 ++++++++++++++++++- 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/koha-tmpl/intranet-tmpl/prog/en/includes/validator-strings.inc b/koha-tmpl/intranet-tmpl/prog/en/includes/validator-strings.inc index 87dde3e610..fbc7c0a26f 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/includes/validator-strings.inc +++ b/koha-tmpl/intranet-tmpl/prog/en/includes/validator-strings.inc @@ -12,6 +12,7 @@ digits: _("Please enter only digits."), equalTo: _("Please enter the same value again."), number: _("Please add amount in valid format: 0.00"), + missing_fields: _("There are some required fields missing from this field set. Please fill them."), maxlength: $.validator.format(_("Please enter no more than {0} characters.")), minlength: $.validator.format(_("Please enter at least {0} characters.")), rangelength: $.validator.format(_("Please enter a value between {0} and {1} characters long.")), diff --git a/koha-tmpl/intranet-tmpl/prog/js/members.js b/koha-tmpl/intranet-tmpl/prog/js/members.js index dad7ead3a3..2cb60fc63c 100644 --- a/koha-tmpl/intranet-tmpl/prog/js/members.js +++ b/koha-tmpl/intranet-tmpl/prog/js/members.js @@ -240,6 +240,7 @@ $(document).ready(function(){ jQuery.validator.messages.phone); $("#entryform").validate({ + ignore: "", rules: { email: { email: true @@ -268,7 +269,23 @@ $(document).ready(function(){ else form.beenSubmitted = true; form.submit(); - } + }, + invalidHandler: function(form, validator) { + var error_msg = jQuery.validator.messages.missing_fields; + // First remove error messages so that it doesn't + // show in fieldset without errors + $("fieldset").each(function(){ + $("#"+$(this).attr("id")+"-error").remove(); + }); + $(validator.errorList).each(function() { + var fieldset = $(this.element.closest("fieldset")); + var fieldset_id = fieldset.attr("id"); + //Add error message only if it doesn't already exist + if(!$("#"+fieldset_id+"-error").length){ + fieldset.find("legend").before(''+error_msg+''); + } + }); + } }); var mrform = $("#manual_restriction_form"); -- 2.34.1