Skip to content

Commit

Permalink
with multiple submit buttons, detect which one was pressed
Browse files Browse the repository at this point in the history
  • Loading branch information
akaspick authored and mislav committed Aug 16, 2010
1 parent c00e908 commit f60d60d
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion src/rails.js
Expand Up @@ -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');
Expand Down Expand Up @@ -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');
Expand Down

3 comments on commit f60d60d

@jdalton
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

@mislav
Copy link
Member

@mislav mislav commented on f60d60d Aug 16, 2010

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@jdalton
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.