Permalink
Browse files

with multiple submit buttons, detect which one was pressed

  • Loading branch information...
akaspick authored and mislav committed Aug 14, 2010
1 parent c00e908 commit f60d60dddcf0dd1f1ae4537b7d25ddaa89b9250d
Showing with 6 additions and 1 deletion.
  1. +6 −1 src/rails.js
View
@@ -80,7 +80,7 @@
if (element.tagName.toLowerCase() === 'form') {
method = element.readAttribute('method') || 'post';
url = element.readAttribute('action');
- params = element.serialize();
+ params = element.serialize({ submit: element.retrieve('rails:submit-button') });
} else {
method = element.readAttribute('data-method') || 'get';
url = element.readAttribute('href');
@@ -142,6 +142,11 @@
event.stop();
});
+ document.on("click", "form input[type=submit]", function(event, button) {
+ // register the pressed submit button
+ event.findElement('form').store('rails:submit-button', button.name || false);
+ });
+
document.on("submit", function(event) {
var form = event.findElement(),
message = form.readAttribute('data-confirm');

3 comments on commit f60d60d

What happens when a form is submitted without clicking the submit button?

Member

mislav replied Aug 16, 2010

Then the first submit button should be serialized. But you're right: if another button was pressed before, the stored value is never cleared and it would appear that this button is forever pressed. Fixed in 386d364

I'm working on some automated tests through Selenium. If anyone has a better suggestion for a tool that would run tests against a mini web-app in headless mode, please speak.

Please sign in to comment.