Skip to content

Commit

Permalink
Move $.fn.submit to form.js
Browse files Browse the repository at this point in the history
  • Loading branch information
kossnocorp committed Jul 13, 2011
1 parent 2945368 commit a29196e
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 20 deletions.
17 changes: 17 additions & 0 deletions src/form.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,4 +59,21 @@
return result.join('&');
};

// ### $.fn.submit
//
// Trigger submit event for form
//
// *Example:*
//
// $('#login_form').submit();
//
$.fn.submit = function () {
return this.each(function () {
try {
this.submit();
return;
} catch(e) {};
});
}

})(Zepto);
9 changes: 0 additions & 9 deletions src/zepto.js
Original file line number Diff line number Diff line change
Expand Up @@ -353,15 +353,6 @@ var Zepto = (function() {
((when !== undefined && !when) || $(this).hasClass(newName)) ?
$(this).removeClass(newName) : $(this).addClass(newName)
});
},
submit: function () {
return this.each(function () {
try {
// Submit first form element
this.submit();
return;
} catch(e) {};
});
}
};

Expand Down
10 changes: 10 additions & 0 deletions test/form.html
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,16 @@ <h1>Zepto DOM unit tests</h1>
t.assertEqual(Function, loginForm.serialize.constructor);
t.assertEqual( 'string', typeof loginForm.serialize() );
t.assertEqual( 'email=koss%40nocorp.me&password=123456', loginForm.serialize() );
},

testFormSubmit: function (t) {
var formSubmitted = false;
$('#login_form').get(0).submit = function (e) {
formSubmitted = true;
e.preventDefault();
};
$('#login_form').submit();
t.assert(formSubmitted);
}

});
Expand Down
11 changes: 0 additions & 11 deletions test/zepto.html
Original file line number Diff line number Diff line change
Expand Up @@ -1533,17 +1533,6 @@ <h1>Zepto DOM unit tests</h1>
t.assert(foo);
},

testFormSubmit: function (t) {
// Test form submit action
var formSubmitted = false;
$('#some_form').get(0).submit = function (e) {
formSubmitted = true;
e.preventDefault();
};
$('#some_form').submit();
t.assert(formSubmitted);
},

testSlice: function (t) {
var $els = $("#slice_test div");
t.assertEqual($els.slice().length, 3);
Expand Down

0 comments on commit a29196e

Please sign in to comment.