Skip to content

Commit

Permalink
Buttons of type button should not submit forms
Browse files Browse the repository at this point in the history
Closes bitovi#63
  • Loading branch information
matthewp committed Sep 5, 2014
1 parent 3d551ed commit 9c9dee6
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 3 deletions.
6 changes: 3 additions & 3 deletions src/mouse.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,9 @@ steal('./synthetic.js', function (Syn) {
}

//submit a form
if (!(Syn.support.clickSubmits) && (nodeName === "input" &&
type === "submit") ||
nodeName === 'button') {
if (!(Syn.support.clickSubmits) && ((nodeName === "input" ||
nodeName === "button") &&
type === "submit")) {

var form = Syn.closest(element, "form");
if (form) {
Expand Down
15 changes: 15 additions & 0 deletions test/qunit/mouse_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ steal("src/synthetic.js", function (Syn) {
"<input type='radio' name='radio' value='radio2' id='radio2'/>" +
"<a href='javascript:doSomething()' id='jsHref'>click me</a>" +
"<a href='#aHash' id='jsHrefHash'>click me</a>" +
"<button id='button' type='button'>Click me</button>" +
"<input type='submit' id='submit'/></div></form>";
},

Expand Down Expand Up @@ -113,6 +114,20 @@ steal("src/synthetic.js", function (Syn) {

Syn.trigger("click", {}, st.g("checkbox"));
});

test("Click a button that is type=button should not trigger form submit", function(){
var timeout = setTimeout(function(){
ok(true, "Form was not submitted");
start();
});
st.binder("outer", "submit", function(ev){
clearTimeout(timeout);
ev.preventDefault();
});

Syn.trigger("click", {}, st.g("button"));
stop();
});

test("Select is changed on click", function () {

Expand Down

0 comments on commit 9c9dee6

Please sign in to comment.