@@ -, +, @@ required - 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. --- .../prog/css/src/staff-global.scss | 1 + .../includes/modals/cataloguing_create_av.inc | 20 ++++--- koha-tmpl/intranet-tmpl/prog/js/cataloging.js | 60 +++++++++++-------- 3 files changed, 47 insertions(+), 34 deletions(-) --- a/koha-tmpl/intranet-tmpl/prog/css/src/staff-global.scss +++ a/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; --- a/koha-tmpl/intranet-tmpl/prog/en/includes/modals/cataloguing_create_av.inc +++ a/koha-tmpl/intranet-tmpl/prog/en/includes/modals/cataloguing_create_av.inc @@ -3,11 +3,10 @@ --- a/koha-tmpl/intranet-tmpl/prog/js/cataloging.js +++ a/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; + } }); + }); --