Skip to content

Commit

Permalink
Add unit test for the new submit_callback option
Browse files Browse the repository at this point in the history
Test currently fails. Not yet implemented.
  • Loading branch information
LearningStation committed Aug 5, 2011
1 parent d4426dd commit 4ddab6a
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 6 deletions.
6 changes: 3 additions & 3 deletions js/uni-form-validation.jquery.js
Original file line number Diff line number Diff line change
Expand Up @@ -580,7 +580,7 @@ jQuery.fn.uniform = function(extended_settings) {
if (settings.prevent_submit || form.hasClass('preventSubmit')) {
// use blur to run the validators on each field
form.find(settings.field_selector).each(function() {
$(this).blur();
$(this).blur();
});

if (form
Expand All @@ -600,7 +600,7 @@ jQuery.fn.uniform = function(extended_settings) {

// qUnit needs to run this function, and still prevent the submit
if (form.parents('#qunit-fixture').length) {
return false;
return false;
}

settings.ask_on_leave = false;
Expand Down Expand Up @@ -657,7 +657,6 @@ jQuery.fn.uniform = function(extended_settings) {
}

// run the validation and if they all pass, we mark the color and move on

for (validator in self.validators) {
if ($input.hasClass(validator)) {
has_validation = true;
Expand Down Expand Up @@ -746,6 +745,7 @@ jQuery.fn.uniform.language = {
* See the validation.md file for more information about these options
*/
jQuery.fn.uniform.defaults = {
submit_callback : false,
prevent_submit : false,
prevent_submit_callback : false,
ask_on_leave : false,
Expand Down
2 changes: 1 addition & 1 deletion js/uni-form-validation.jquery.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

24 changes: 22 additions & 2 deletions test/form.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ test("Ask on Leave", function() {
);

jQuery('#email', $form).val('spam@example.com');
jQuery(window).trigger('beforeunload')
jQuery(window).trigger('beforeunload');

equals(
prompted,
true,
Expand All @@ -38,6 +38,7 @@ test("Ask on Leave", function() {
test("Prevent submit", function() {
$form = jQuery('#qunit-form');
$form.uniform({prevent_submit : true});

jQuery('#email', $form)
.trigger('focus')
.val('invalid.email')
Expand All @@ -51,3 +52,22 @@ test("Prevent submit", function() {
);
});

test("Submit callback is executed", function() {
var was_called = false;

$form = jQuery('#qunit-form');
$form.uniform({
submit_callback : function() {
was_called = true;
return false;
}
});

$form.trigger('submit');

equals(
was_called,
true,
"Submit callback was not called"
);
});

0 comments on commit 4ddab6a

Please sign in to comment.