From 0f95ac23e1a62ef1af22bf7a49f3cb259d5426db Mon Sep 17 00:00:00 2001 From: Emmi Takkinen Date: Fri, 15 Sep 2023 11:19:35 +0300 Subject: [PATCH 1/3] 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 | 17 +++++++++++++++++ 2 files changed, 18 insertions(+) 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 dbd32806e5..4335a7f0c3 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 section. Please complete 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 a20561cfe0..8e7e9b6823 100644 --- a/koha-tmpl/intranet-tmpl/prog/js/members.js +++ b/koha-tmpl/intranet-tmpl/prog/js/members.js @@ -322,6 +322,7 @@ $(document).ready(function () { ); $("#entryform").validate({ + ignore: "", rules: { email: { email: true, @@ -351,6 +352,22 @@ $(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).parents('[id*="memberentry_"]'); + var fieldset_id = fieldset.attr("id"); + //Add error message only if it doesn't already exist + if(!$("#"+fieldset_id+"-error").length){ + fieldset.find("legend").after(''+error_msg+''); + } + }); + } }); var mrform = $("#manual_restriction_form"); -- 2.34.1