@@ -, +, @@
"1 mandatory fields empty (highlighted)".
- In a framework, make sure you have in item field :
An optionnal 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
- Empty $s and Save
- Re-edit this item
- Empty $r and save
---
koha-tmpl/intranet-tmpl/prog/en/js/cataloging.js | 17 +++++++++++++++++
.../prog/en/modules/cataloguing/additem.tt | 22 +++++-----------------
2 files changed, 22 insertions(+), 17 deletions(-)
--- a/koha-tmpl/intranet-tmpl/prog/en/js/cataloging.js
+++ a/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;
+}
--- a/koha-tmpl/intranet-tmpl/prog/en/modules/cataloguing/additem.tt
+++ a/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) {
--