From 9f5f05d40d2ee8a357d25472cd200a7f748de0e2 Mon Sep 17 00:00:00 2001 From: Fridolyn SOMERS Date: Fri, 5 Jul 2013 15:20:59 +0200 Subject: [PATCH] Bug 10543: fix false warnings from checks of mandatory item fields Under certain circumstances, when editing an item, you get a popup warning "1 mandatory fields empty (highlighted)". Even though all mandatory fields are filled in. This occurs when there is a field with a huge content (more than 100 characters) that gets displayed in a textarea instead of input. This patch corrects the Javascript form check by using siblings(). Also adds a more precise filter to find mandatory inputs because looking in full page may bring unwanted results. Test plan : - In a framework, make sure you have in item field : An optional subfield (without authorised value), then a mandatory subfield, then an optional subfield next to mandatory subfield For example : $i (optional), $r (mandatory) and $s (optional) - Open a biblio record and create a new item - Enter more than 100 characters in $i, fill $r and $s - Click "Add item" - Edit this item => You get a textarea for $i - Empty $s and Save => Without patch, you get a warning and form is not saved and you see that $s is yellow while it should be $r => With patch, form is saved - Re-edit this item - Empty $r and save => You get a warning and form is not saved Signed-off-by: Srdjan Signed-off-by: Katrin Fischer Notes on last patch. Signed-off-by: Galen Charlton (cherry picked from commit 651ea298ea90742a2c56bbb693a4fbbb0064d5b2) Signed-off-by: Tomas Cohen Arazi Couldn't reproduce using $i as in the test plan, but $o triggered the problem, which this patch series fix. --- .../intranet-tmpl/prog/en/js/cataloging.js | 17 ++++++++++++++ .../prog/en/modules/cataloguing/additem.tt | 22 +++++-------------- 2 files changed, 22 insertions(+), 17 deletions(-) diff --git a/koha-tmpl/intranet-tmpl/prog/en/js/cataloging.js b/koha-tmpl/intranet-tmpl/prog/en/js/cataloging.js index 614e6982ce..6b49579586 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/js/cataloging.js +++ b/koha-tmpl/intranet-tmpl/prog/en/js/cataloging.js @@ -464,3 +464,20 @@ function CloneItemSubfield(original){ // insert this line on the page original.parentNode.insertBefore(clone,original.nextSibling); } + +/** + * Check mandatory subfields of a cataloging form and adds missing class to those who are empty.
+ * @param p the parent object of subfields to check + * @return the number of empty mandatory subfields + */ +function CheckMandatorySubfields(p){ + var total = 0; + $(p).find(".subfield_line input[name='mandatory'][value='1']").each(function(i){ + var editor = $(this).siblings("[name='field_value']"); + if (!editor.val()) { + editor.addClass("missing"); + total++; + } + }); + return total; +} diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/cataloguing/additem.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/cataloguing/additem.tt index 5213fc30e3..ec7a6acf03 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/cataloguing/additem.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/cataloguing/additem.tt @@ -40,27 +40,15 @@ function active(numlayer) } } function Check(f) { - var total_errors=0; - $("input[name='mandatory'],select[name='mandatory']").each(function(i){ - if($(this).val() == 1){ - var mandatory_field = $("input[name='field_value'],select[name='field_value']").eq(i); - if(mandatory_field.val() == ''){ - mandatory_field.addClass("missing"); - total_errors++; - } - } - }); - - var alertString2; - if (total_errors==0) { - return true; - } else { - alertString2 = _("Form not submitted because of the following problem(s)"); + var total_errors = CheckMandatorySubfields(f); + if (total_errors > 0) { + var alertString2 = _("Form not submitted because of the following problem(s)"); alertString2 += "\n------------------------------------------------------------------------------------\n"; - alertString2 += "\n- "+ total_errors+_(" mandatory fields empty (highlighted)"); + alertString2 += "\n- "+ total_errors + _(" mandatory fields empty (highlighted)"); alert(alertString2); return false; } + return true; } function CheckMultipleAdd(f) { -- 2.39.5