From 9b9e9614d2ce3c2cd9715e7a9924d0c3aaceac3b Mon Sep 17 00:00:00 2001 From: Martin Renvoize Date: Tue, 22 Aug 2023 16:11:29 +0100 Subject: [PATCH] Bug 29002: Always reset the place/edit form on modal close Signed-off-by: Martin Renvoize Signed-off-by: Janet McGowan Signed-off-by: Caroline Cyr La Rose Signed-off-by: Laurence Rault Signed-off-by: Kyle M Hall Signed-off-by: Tomas Cohen Arazi --- .../prog/js/place_booking_modal.js | 45 ++++++++----------- 1 file changed, 19 insertions(+), 26 deletions(-) diff --git a/koha-tmpl/intranet-tmpl/prog/js/place_booking_modal.js b/koha-tmpl/intranet-tmpl/prog/js/place_booking_modal.js index 467fb3e188..d6522e8b09 100644 --- a/koha-tmpl/intranet-tmpl/prog/js/place_booking_modal.js +++ b/koha-tmpl/intranet-tmpl/prog/js/place_booking_modal.js @@ -1,7 +1,7 @@ $('#placeBookingModal').on('show.bs.modal', function(e) { var button = $(e.relatedTarget); var biblionumber = button.data('biblionumber'); - var itemnumber = button.data('itemnumber') || 0; + var itemnumber = button.data('itemnumber'); $('#booking_biblio_id').val(biblionumber); // Get booking id if this is an edit @@ -173,20 +173,18 @@ $('#placeBookingModal').on('show.bs.modal', function(e) { bookable++; // Populate item select if (!($('#booking_item_id').find("option[value='" + item.item_id + "']").length)) { - if (itemnumber && itemnumber == item.item_id) { - // Create a DOM Option and pre-select by default - var newOption = new Option(escape_str(item.external_id), item.item_id, true, true); - // Append it to the select - $('#booking_item_id').append(newOption); - } else { - // Create a DOM Option and de-select by default - var newOption = new Option(escape_str(item.external_id), item.item_id, false, false); - // Append it to the select - $('#booking_item_id').append(newOption); - } + // Create a DOM Option and de-select by default + var newOption = new Option(escape_str(item.external_id), item.item_id, false, false); + // Append it to the select + $('#booking_item_id').append(newOption); } } + // If passed an itemnumber, pre-select + if (itemnumber) { + $('#booking_item_id').val(itemnumber); + } + // Redraw select with new options and enable $('#booking_item_id').trigger('change'); $("#booking_item_id").prop("disabled", false); @@ -426,13 +424,6 @@ $("#placeBookingForm").on('submit', function(e) { // Close modal $('#placeBookingModal').modal('hide'); - - // Reset form - $('#booking_patron_id').val(null).trigger('change'); - $('#booking_item_id').val(null).trigger('change'); - $("#period").get(0)._flatpickr.clear(); - $('#booking_start_date').val(''); - $('#booking_end_date').val(''); }); posting.fail(function(data) { @@ -476,13 +467,6 @@ $("#placeBookingForm").on('submit', function(e) { // Close modal $('#placeBookingModal').modal('hide'); - - // Reset form - $('#booking_patron_id').val(null).trigger('change'); - $('#booking_item_id').val(null).trigger('change'); - $("#period").get(0)._flatpickr.clear(); - $('#booking_start_date').val(''); - $('#booking_end_date').val(''); }); putting.fail(function(data) { @@ -490,3 +474,12 @@ $("#placeBookingForm").on('submit', function(e) { }); } }); + +$('#placeBookingModal').on('hidden.bs.modal', function (e) { + $('#booking_patron_id').val(null).trigger('change'); + $('#booking_item_id').val(null).trigger('change'); + $("#period").get(0)._flatpickr.clear(); + $('#booking_start_date').val(''); + $('#booking_end_date').val(''); + $('#booking_id').val(''); +}) -- 2.39.5