From 65f09b685c13c7125131409ebae8403d4450ba09 Mon Sep 17 00:00:00 2001 From: Ere Maijala <ere.maijala@helsinki.fi> Date: Wed, 9 Mar 2016 09:24:34 +0200 Subject: [PATCH] Improved the clicked submit button detection to work on all platforms and cases where the form has multiple submit buttons. --- themes/bootstrap3/js/lightbox.js | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/themes/bootstrap3/js/lightbox.js b/themes/bootstrap3/js/lightbox.js index 5a6cb8f8f7d..f2ee7377eed 100644 --- a/themes/bootstrap3/js/lightbox.js +++ b/themes/bootstrap3/js/lightbox.js @@ -45,6 +45,15 @@ VuFind.lightbox = (function() { _modal.modal('show'); // Attach capturing events _modalBody.find('a').on('click', _constrainLink); + // Handle submit buttons attached to a form as well as those in a form. Store + // information about which button was clicked here as checking focused button + // doesn't work on all browsers and platforms. + _modalBody.find('[type=submit]').click(function() { + var form = $(this).prop('form') || $(this).closest('form')[0]; + $(form.elements).filter('[type=submit]').removeAttr('clicked'); + $(this).attr('clicked', true); + }); + var forms = _modalBody.find('form'); for(var i=0;i<forms.length;i++) { $(forms[i]).on('submit', _formSubmit); @@ -141,7 +150,7 @@ VuFind.lightbox = (function() { var data = $(form).serializeArray(); data.push({'name':'layout', 'value':'lightbox'}); // Return in lightbox, please // Add submit button information - var submit = $(form).find('[type=submit]'); + var submit = $(form).find('[type=submit][clicked]'); if (submit.length > 0) { submit.attr('disabled', 'disabled'); var name = submit.attr('name') ? submit.attr('name') : 'submit'; -- GitLab