Detect form button in JS form submission handler

This commit is contained in:
Thomas Gelf 2014-03-28 14:53:37 +00:00
parent bafa8cc032
commit a5e41f6c08
1 changed files with 11 additions and 2 deletions

View File

@ -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);