Enhancement for 'ajax' form class: submit buttons behave more like normal submissions, submitting their name/values through a hidden field.

This should work well for simple cases, but could conceivably create false positives if there's a click handler on the specific buttons, depending on whether event processing passes it on. Double-check if you're doing such forms along with the 'ajax' class!
This commit is contained in:
Brion Vibber 2011-03-23 15:21:31 -07:00
parent 265f9af6f7
commit 2707a481e4
2 changed files with 13 additions and 1 deletions

View File

@ -1464,6 +1464,18 @@ var SN = { // StatusNet
SN.U.FormXHR($(this));
return false;
});
$('form.ajax input[type=submit]').live('click', function() {
// Some forms rely on knowing which submit button was clicked.
// Save a hidden input field which'll be picked up during AJAX
// submit...
var button = $(this);
var form = button.closest('form');
form.find('.hidden-submit-button').remove();
$('<input class="hidden-submit-button" type="hidden" />')
.attr('name', button.attr('name'))
.val(button.val())
.appendTo(form);
});
},
/**

2
js/util.min.js vendored

File diff suppressed because one or more lines are too long