From a5e41f6c08f9beb0227f1780bf93e6ca2f6fbb46 Mon Sep 17 00:00:00 2001 From: Thomas Gelf Date: Fri, 28 Mar 2014 14:53:37 +0000 Subject: [PATCH] Detect form button in JS form submission handler --- public/js/icinga/events.js | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/public/js/icinga/events.js b/public/js/icinga/events.js index 68df1d485..e19c34a5d 100644 --- a/public/js/icinga/events.js +++ b/public/js/icinga/events.js @@ -229,6 +229,7 @@ var regex = new RegExp('&', 'g'); var url = $form.attr('action').replace(regex, '&'); // WHY?? var method = $form.attr('method'); + var $button = $('input[type=submit]:focus', $form); var $target; var data; @@ -238,6 +239,10 @@ method = method.toUpperCase(); } + if ($button.length === 0) { + $button = $('input[type=submit]', $form).first(); + } + event.stopPropagation(); event.preventDefault(); @@ -250,9 +255,13 @@ } else { data = $form.serializeArray(); - // TODO: Check button if (typeof autosubmit === 'undefined' || ! autosubmit) { - data.push({ name: 'btn_submit', value: 'yesss' }); + if ($button.length) { + data.push({ + name: $button.attr('name'), + value: $button.attr('value') + }); + } } } icinga.loader.loadUrl(url, $target, data, method);