From 966ba1268300e64f2a1644ae8c28f7e39e92997a Mon Sep 17 00:00:00 2001 From: Owen Leonard Date: Wed, 15 Sep 2021 17:40:19 +0000 Subject: [PATCH] Bug 29030: Make authorized value and description fields required This patch modifies the markup of the "Create a new authorized value" modal so that a minimum set of fields is required: Authorized value and description. The patch also modifies the JavaScript which handles the submission so that the jQuery Validation plugin can handle the field checks. The spelling "authorised" is changed to "authorized" following coding guidelines. To test, apply the patch and rebuild the staff interface CSS (https://wiki.koha-community.org/wiki/Working_with_SCSS_in_the_OPAC_and_staff_client). - Locate a record in the catalog which has items and open an item for editing. - In the add item form, test the process of adding an authorized value on the fly with the following fields: Withdrawn, Lost, Damaged, Use restrictions, Not for loan, Collection code, Shelving location, and Shelving control number. - In each case you should be able to type a new value in the dropdown's search box and be shown the option "Select to create." - Selecting should trigger a modal window, "Create a new authorized value." - Test that both "Authorized value" and "Description" fields are required, and the form can't be submitted without them. - Test that an error message shows up when you submit an authorized value which already exists, e.g. authval "1" for "DAMAGED." - After triggering this error, click the "Cancel" button and try creating another new authorized value. When the modal reopens the form should be reset: No previously-entered data, no error messages. - Submitting a valid form with a new authorized value should work correctly. The modal window should close automatically. Signed-off-by: David Nind Signed-off-by: Katrin Fischer --- .../intranet-tmpl/prog/css/src/staff-global.scss | 1 + .../en/includes/modals/cataloguing_create_av.inc | 20 ++++---- koha-tmpl/intranet-tmpl/prog/js/cataloging.js | 60 +++++++++++++--------- 3 files changed, 47 insertions(+), 34 deletions(-) diff --git a/koha-tmpl/intranet-tmpl/prog/css/src/staff-global.scss b/koha-tmpl/intranet-tmpl/prog/css/src/staff-global.scss index 9d8f5e8069..809e0a506b 100644 --- a/koha-tmpl/intranet-tmpl/prog/css/src/staff-global.scss +++ b/koha-tmpl/intranet-tmpl/prog/css/src/staff-global.scss @@ -2371,6 +2371,7 @@ td { .dialog { border-radius: 0; border-width: 1px 0 0 0; + clear: both; margin: 15px -15px -15px -15px; padding: 15px; text-align: left; diff --git a/koha-tmpl/intranet-tmpl/prog/en/includes/modals/cataloguing_create_av.inc b/koha-tmpl/intranet-tmpl/prog/en/includes/modals/cataloguing_create_av.inc index 995a5ae337..0618474740 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/includes/modals/cataloguing_create_av.inc +++ b/koha-tmpl/intranet-tmpl/prog/en/includes/modals/cataloguing_create_av.inc @@ -3,11 +3,10 @@ diff --git a/koha-tmpl/intranet-tmpl/prog/js/cataloging.js b/koha-tmpl/intranet-tmpl/prog/js/cataloging.js index a2d7b4a2aa..e037f6ff82 100644 --- a/koha-tmpl/intranet-tmpl/prog/js/cataloging.js +++ b/koha-tmpl/intranet-tmpl/prog/js/cataloging.js @@ -1,3 +1,4 @@ +/* global __ */ /* exported openAuth ExpandField CloneField CloneSubfield UnCloneField CloneItemSubfield CheckMandatorySubfields */ /* @@ -588,30 +589,39 @@ $(document).ready(function() { Select2Utils.initSelect2($('.subfield_line select[data-category!=""]')); } - $("#add_new_av").on("submit", function(){ - var category = $(this).find('input[name="category"]').val(); - var value = $(this).find('input[name="value"]').val(); - var description = $(this).find('input[name="description"]').val(); - var opac_description = $(this).find('input[name="opac_description"]').val(); - - var data = "category="+encodeURIComponent(category) - +"&value="+encodeURIComponent(value) - +"&description="+encodeURIComponent(description) - +"&opac_description="+encodeURIComponent(opac_description); - - $.ajax({ - type: "POST", - url: "/cgi-bin/koha/svc/authorised_values", - data: data, - success: function(response) { - $('#avCreate').modal('hide'); - - $(current_select2).append(''); - }, - error: function(err) { - $("#avCreate .error").html(_("Something went wrong, maybe the value already exists?")) - } - }); - return false; + $("#avCreate").on("hidden.bs.modal", function(){ + add_new_av.resetForm(); /* resets form state for jQuery Validate plugin */ + $("#add_new_av")[0].reset(); + $(".avCreate_error").hide(); + }); + + var add_new_av = $("#add_new_av").validate({ + submitHandler: function(form) { + var category = form.category.value; + var value = form.value.value; + var description = form.description.value; + var opac_description = form.opac_description.value; + + var data = "category="+encodeURIComponent(category) + +"&value="+encodeURIComponent(value) + +"&description="+encodeURIComponent(description) + +"&opac_description="+encodeURIComponent(opac_description); + $.ajax({ + type: "POST", + url: "/cgi-bin/koha/svc/authorised_values", + data: data, + success: function(response) { + $('#avCreate').modal('hide'); + + $(current_select2).append(''); + $("#avCreate").modal("hide"); + }, + error: function() { + $(".avCreate_error").html(__("Something went wrong. Maybe the value already exists?")).show(); + } + }); + return false; + } }); + }); -- 2.11.0