|
|
@@ -539,6 +539,8 @@ describe('enable validators', function() {
|
|
|
});
|
|
|
});
|
|
|
|
|
|
+var defaultOptions = $.fn.bootstrapValidator.DEFAULT_OPTIONS;
|
|
|
+
|
|
|
TestSuite = $.extend({}, TestSuite, {
|
|
|
Event: {
|
|
|
onEmailValid: function(e, data) {
|
|
|
@@ -1024,8 +1026,6 @@ describe('event field trigger with default events', function() {
|
|
|
});
|
|
|
|
|
|
describe('event form trigger with events changed', function() {
|
|
|
- var defaultOptions = $.fn.bootstrapValidator.DEFAULT_OPTIONS;
|
|
|
-
|
|
|
beforeEach(function() {
|
|
|
$.fn.bootstrapValidator.DEFAULT_OPTIONS = $.extend({}, $.fn.bootstrapValidator.DEFAULT_OPTIONS, {
|
|
|
events: {
|
|
|
@@ -1072,8 +1072,8 @@ describe('event form trigger with events changed', function() {
|
|
|
});
|
|
|
|
|
|
afterEach(function() {
|
|
|
- $.fn.bootstrapValidator.DEFAULT_OPTIONS = defaultOptions;
|
|
|
$('#eventForm2').bootstrapValidator('destroy').remove();
|
|
|
+ $.fn.bootstrapValidator.DEFAULT_OPTIONS = defaultOptions;
|
|
|
});
|
|
|
|
|
|
it('triggers bv.form.success', function() {
|
|
|
@@ -1100,8 +1100,6 @@ describe('event form trigger with events changed', function() {
|
|
|
});
|
|
|
|
|
|
describe('event field trigger with events changed', function() {
|
|
|
- var defaultOptions = $.fn.bootstrapValidator.DEFAULT_OPTIONS;
|
|
|
-
|
|
|
beforeEach(function() {
|
|
|
$.fn.bootstrapValidator.DEFAULT_OPTIONS = $.extend({}, $.fn.bootstrapValidator.DEFAULT_OPTIONS, {
|
|
|
events: {
|
|
|
@@ -1148,8 +1146,8 @@ describe('event field trigger with events changed', function() {
|
|
|
});
|
|
|
|
|
|
afterEach(function() {
|
|
|
- $.fn.bootstrapValidator.DEFAULT_OPTIONS = defaultOptions;
|
|
|
$('#eventForm4').bootstrapValidator('destroy').remove();
|
|
|
+ $.fn.bootstrapValidator.DEFAULT_OPTIONS = defaultOptions;
|
|
|
});
|
|
|
|
|
|
it('triggers success.field.bv', function() {
|
|
|
@@ -1995,6 +1993,169 @@ describe('message', function() {
|
|
|
});
|
|
|
});
|
|
|
|
|
|
+describe('submit', function() {
|
|
|
+ var submitted, originalTimeout;
|
|
|
+
|
|
|
+ $.fn.bootstrapValidator.validators.fake_remote = {
|
|
|
+ validate: function(validator, $field, options) {
|
|
|
+ var dfd = new $.Deferred();
|
|
|
+ setTimeout(function() {
|
|
|
+ dfd.resolve($field, 'fake_remote', { valid: options.valid });
|
|
|
+ }, 0);
|
|
|
+ return dfd;
|
|
|
+ }
|
|
|
+ };
|
|
|
+
|
|
|
+ beforeEach(function() {
|
|
|
+ $([
|
|
|
+ '<form id="submitForm" class="form-horizontal" role="form">',
|
|
|
+ '<div class="form-group">',
|
|
|
+ '<input name="username" type="text" class="form-control" value="me" required />',
|
|
|
+ '</div>',
|
|
|
+ '<button id="sendButton" type="submit" class="btn btn-default">Send</button>',
|
|
|
+ '</form>'
|
|
|
+ ].join('\n')).appendTo('body');
|
|
|
+
|
|
|
+ this.$form = $('#submitForm');
|
|
|
+ this.$form
|
|
|
+ .bootstrapValidator()
|
|
|
+ .on('success.form.bv', function(e) {
|
|
|
+ e.preventDefault();
|
|
|
+ ++submitted;
|
|
|
+ })
|
|
|
+ .submit(function(e) {
|
|
|
+ e.preventDefault();
|
|
|
+ });
|
|
|
+
|
|
|
+ submitted = 0;
|
|
|
+ this.bv = this.$form.data('bootstrapValidator');
|
|
|
+ this.$username = this.bv.getFieldElements('username');
|
|
|
+
|
|
|
+ originalTimeout = jasmine.DEFAULT_TIMEOUT_INTERVAL;
|
|
|
+ jasmine.DEFAULT_TIMEOUT_INTERVAL = 10000;
|
|
|
+ });
|
|
|
+
|
|
|
+ afterEach(function() {
|
|
|
+ $('#submitForm').bootstrapValidator('destroy').remove();
|
|
|
+ jasmine.DEFAULT_TIMEOUT_INTERVAL = originalTimeout;
|
|
|
+ });
|
|
|
+
|
|
|
+ // #481
|
|
|
+ it('without callback nor remote', function(done) {
|
|
|
+ $('#sendButton').click();
|
|
|
+ setTimeout(function() {
|
|
|
+ expect(submitted).toBe(1);
|
|
|
+ done();
|
|
|
+ }, 0);
|
|
|
+ });
|
|
|
+
|
|
|
+ // #481
|
|
|
+ it('with callback returning true', function(done) {
|
|
|
+ this.bv.addField('username', {
|
|
|
+ validators: {
|
|
|
+ callback: {
|
|
|
+ message: 'Please enter an username',
|
|
|
+ callback: function(value, validator, $field) {
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ });
|
|
|
+ $('#sendButton').click();
|
|
|
+ setTimeout(function() {
|
|
|
+ expect(submitted).toBe(1);
|
|
|
+ done();
|
|
|
+ }, 0);
|
|
|
+ });
|
|
|
+
|
|
|
+ // #481
|
|
|
+ it('with callback returning false', function(done) {
|
|
|
+ this.bv.addField('username', {
|
|
|
+ validators: {
|
|
|
+ callback: {
|
|
|
+ message: 'Please enter an username',
|
|
|
+ callback: function(value, validator, $field) {
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ });
|
|
|
+ $('#sendButton').click();
|
|
|
+ setTimeout(function() {
|
|
|
+ expect(submitted).toBe(0);
|
|
|
+ done();
|
|
|
+ }, 0);
|
|
|
+ });
|
|
|
+
|
|
|
+ // #481
|
|
|
+ it('with remote returning true', function(done) {
|
|
|
+ this.bv.addField('username', {
|
|
|
+ validators: {
|
|
|
+ remote: {
|
|
|
+ url: 'http://echo.jsontest.com/valid/true',
|
|
|
+ message: 'The username is not available'
|
|
|
+ }
|
|
|
+ }
|
|
|
+ });
|
|
|
+ $('#sendButton').click();
|
|
|
+ setTimeout(function() {
|
|
|
+ expect(submitted).toBe(1);
|
|
|
+ done();
|
|
|
+ }, 3000);
|
|
|
+ });
|
|
|
+
|
|
|
+ // #481
|
|
|
+ it('with remote returning false', function(done) {
|
|
|
+ this.bv.addField('username', {
|
|
|
+ validators: {
|
|
|
+ remote: {
|
|
|
+ url: 'http://echo.jsontest.com/valid/false',
|
|
|
+ message: 'The username is not available'
|
|
|
+ }
|
|
|
+ }
|
|
|
+ });
|
|
|
+ $('#sendButton').click();
|
|
|
+ setTimeout(function() {
|
|
|
+ expect(submitted).toBe(0);
|
|
|
+ done();
|
|
|
+ }, 3000);
|
|
|
+ });
|
|
|
+
|
|
|
+ // #481
|
|
|
+ it('with fake remote returning true', function(done) {
|
|
|
+ this.bv.addField('username', {
|
|
|
+ validators: {
|
|
|
+ fake_remote: {
|
|
|
+ message: 'The username is not available',
|
|
|
+ valid: true
|
|
|
+ }
|
|
|
+ }
|
|
|
+ });
|
|
|
+ $('#sendButton').click();
|
|
|
+ setTimeout(function() {
|
|
|
+ expect(submitted).toBe(1);
|
|
|
+ done();
|
|
|
+ }, 100);
|
|
|
+ });
|
|
|
+
|
|
|
+ // #481
|
|
|
+ it('with fake remote returning false', function(done) {
|
|
|
+ this.bv.addField('username', {
|
|
|
+ validators: {
|
|
|
+ fake_remote: {
|
|
|
+ message: 'The username is not available',
|
|
|
+ valid: false
|
|
|
+ }
|
|
|
+ }
|
|
|
+ });
|
|
|
+ $('#sendButton').click();
|
|
|
+ setTimeout(function() {
|
|
|
+ expect(submitted).toBe(0);
|
|
|
+ done();
|
|
|
+ }, 100);
|
|
|
+ });
|
|
|
+});
|
|
|
+
|
|
|
describe('verbose option', function() {
|
|
|
beforeEach(function() {
|
|
|
$([
|