|
|
@@ -54,6 +54,192 @@ describe('api', function() {
|
|
|
});
|
|
|
});
|
|
|
|
|
|
+var My = {
|
|
|
+ NameSpace: {
|
|
|
+ onEmailValid: function(e, data) {
|
|
|
+ $('#msg').html('My.NameSpace.onEmailValid() called, ' + data.field + ' is valid');
|
|
|
+ },
|
|
|
+
|
|
|
+ onEmailInvalid: function(e, data) {
|
|
|
+ $('#msg').html('My.NameSpace.onEmailInvalid() called, ' + data.field + ' is invalid');
|
|
|
+ },
|
|
|
+
|
|
|
+ onFormValid: function(e) {
|
|
|
+ $('#msg').html('My.NameSpace.onFormValid() called, form ' + $(e.target).attr('id') + ' is valid');
|
|
|
+ },
|
|
|
+
|
|
|
+ onFormInvalid: function(e) {
|
|
|
+ $('#msg').html('My.NameSpace.onFormInvalid() called, form ' + $(e.target).attr('id') + ' is invalid');
|
|
|
+ }
|
|
|
+ }
|
|
|
+};
|
|
|
+
|
|
|
+// ---
|
|
|
+// Form events
|
|
|
+// ---
|
|
|
+
|
|
|
+function onFormValid(e) {
|
|
|
+ $('#msg').html('form ' + $(e.target).attr('id') + ' is valid');
|
|
|
+};
|
|
|
+
|
|
|
+function onFormInvalid(e) {
|
|
|
+ $('#msg').html('form ' + $(e.target).attr('id') + ' is invalid');
|
|
|
+};
|
|
|
+
|
|
|
+describe('event form attribute callback global', function() {
|
|
|
+ beforeEach(function() {
|
|
|
+ $([
|
|
|
+ '<form class="form-horizontal" id="eventForm" data-bv-onsuccess="onFormValid" data-bv-onerror="onFormInvalid" >',
|
|
|
+ '<div id="msg"></div>',
|
|
|
+ '<div class="form-group">',
|
|
|
+ '<input type="text" name="email" required data-bv-emailaddress />',
|
|
|
+ '</div>',
|
|
|
+ '</form>'
|
|
|
+ ].join('\n')).appendTo('body');
|
|
|
+
|
|
|
+ $('#eventForm').bootstrapValidator();
|
|
|
+
|
|
|
+ this.bv = $('#eventForm').data('bootstrapValidator');
|
|
|
+ this.$email = this.bv.getFieldElements('email');
|
|
|
+ });
|
|
|
+
|
|
|
+ afterEach(function() {
|
|
|
+ $('#eventForm').bootstrapValidator('destroy').remove();
|
|
|
+ });
|
|
|
+
|
|
|
+ it('call data-bv-onsuccess', function() {
|
|
|
+ this.$email.val('email@domain.com');
|
|
|
+ this.bv.validate();
|
|
|
+ expect($('#msg').html()).toEqual('form eventForm is valid');
|
|
|
+ });
|
|
|
+
|
|
|
+ it('call data-bv-onerror', function() {
|
|
|
+ this.$email.val('email@domain');
|
|
|
+ this.bv.validate();
|
|
|
+ expect($('#msg').html()).toEqual('form eventForm is invalid');
|
|
|
+ });
|
|
|
+});
|
|
|
+
|
|
|
+describe('event form attribute callback namespace', function() {
|
|
|
+ beforeEach(function() {
|
|
|
+ $([
|
|
|
+ '<form class="form-horizontal" id="eventForm" data-bv-onsuccess="My.NameSpace.onFormValid" data-bv-onerror="My.NameSpace.onFormInvalid" >',
|
|
|
+ '<div id="msg"></div>',
|
|
|
+ '<div class="form-group">',
|
|
|
+ '<input type="text" name="email" required data-bv-emailaddress />',
|
|
|
+ '</div>',
|
|
|
+ '</form>'
|
|
|
+ ].join('\n')).appendTo('body');
|
|
|
+
|
|
|
+ $('#eventForm').bootstrapValidator();
|
|
|
+
|
|
|
+ this.bv = $('#eventForm').data('bootstrapValidator');
|
|
|
+ this.$email = this.bv.getFieldElements('email');
|
|
|
+ });
|
|
|
+
|
|
|
+ afterEach(function() {
|
|
|
+ $('#eventForm').bootstrapValidator('destroy').remove();
|
|
|
+ });
|
|
|
+
|
|
|
+ it('call data-bv-onsuccess', function() {
|
|
|
+ this.$email.val('email@domain.com');
|
|
|
+ this.bv.validate();
|
|
|
+ expect($('#msg').html()).toEqual('My.NameSpace.onFormValid() called, form eventForm is valid');
|
|
|
+ });
|
|
|
+
|
|
|
+ it('call data-bv-onerror', function() {
|
|
|
+ this.$email.val('email@domain');
|
|
|
+ this.bv.validate();
|
|
|
+ expect($('#msg').html()).toEqual('My.NameSpace.onFormInvalid() called, form eventForm is invalid');
|
|
|
+ });
|
|
|
+});
|
|
|
+
|
|
|
+describe('event form trigger', function() {
|
|
|
+ beforeEach(function() {
|
|
|
+ $([
|
|
|
+ '<form class="form-horizontal" id="eventForm">',
|
|
|
+ '<div id="msg"></div>',
|
|
|
+ '<div class="form-group">',
|
|
|
+ '<input type="text" name="email" data-bv-emailaddress />',
|
|
|
+ '</div>',
|
|
|
+ '</form>'
|
|
|
+ ].join('\n')).appendTo('body');
|
|
|
+
|
|
|
+ $('#eventForm')
|
|
|
+ .bootstrapValidator()
|
|
|
+ .on('success.form.bv', function(e) {
|
|
|
+ $('#msg').html('form ' + $(e.target).attr('id') + ' triggered success.form.bv event');
|
|
|
+ })
|
|
|
+ .on('error.form.bv', function(e) {
|
|
|
+ $('#msg').html('form ' + $(e.target).attr('id') + ' triggered error.form.bv event');
|
|
|
+ });
|
|
|
+
|
|
|
+ this.bv = $('#eventForm').data('bootstrapValidator');
|
|
|
+ this.$email = this.bv.getFieldElements('email');
|
|
|
+ });
|
|
|
+
|
|
|
+ afterEach(function() {
|
|
|
+ $('#eventForm').bootstrapValidator('destroy').remove();
|
|
|
+ });
|
|
|
+
|
|
|
+ it('trigger success.form.bv', function() {
|
|
|
+ this.$email.val('email@domain.com');
|
|
|
+ this.bv.validate();
|
|
|
+ expect($('#msg').html()).toEqual('form eventForm triggered success.form.bv event');
|
|
|
+ });
|
|
|
+
|
|
|
+ it('trigger error.form.bv', function() {
|
|
|
+ this.$email.val('email@domain');
|
|
|
+ this.bv.validate();
|
|
|
+ expect($('#msg').html()).toEqual('form eventForm triggered error.form.bv event');
|
|
|
+ });
|
|
|
+});
|
|
|
+
|
|
|
+describe('event form programmatically', function() {
|
|
|
+ beforeEach(function() {
|
|
|
+ $([
|
|
|
+ '<form class="form-horizontal" id="eventForm">',
|
|
|
+ '<div id="msg"></div>',
|
|
|
+ '<div class="form-group">',
|
|
|
+ '<input type="text" name="email" data-bv-emailaddress />',
|
|
|
+ '</div>',
|
|
|
+ '</form>'
|
|
|
+ ].join('\n')).appendTo('body');
|
|
|
+
|
|
|
+ $('#eventForm').bootstrapValidator({
|
|
|
+ onSuccess: function(e) {
|
|
|
+ $('#msg').html('onSuccess() called');
|
|
|
+ },
|
|
|
+ onError: function(e) {
|
|
|
+ $('#msg').html('onError() called');
|
|
|
+ }
|
|
|
+ });
|
|
|
+
|
|
|
+ this.bv = $('#eventForm').data('bootstrapValidator');
|
|
|
+ this.$email = this.bv.getFieldElements('email');
|
|
|
+ });
|
|
|
+
|
|
|
+ afterEach(function() {
|
|
|
+ $('#eventForm').bootstrapValidator('destroy').remove();
|
|
|
+ });
|
|
|
+
|
|
|
+ it('call onSuccess()', function() {
|
|
|
+ this.$email.val('email@domain.com');
|
|
|
+ this.bv.validate();
|
|
|
+ expect($('#msg').html()).toEqual('onSuccess() called');
|
|
|
+ });
|
|
|
+
|
|
|
+ it('call onError()', function() {
|
|
|
+ this.$email.val('email@domain');
|
|
|
+ this.bv.validate();
|
|
|
+ expect($('#msg').html()).toEqual('onError() called');
|
|
|
+ });
|
|
|
+});
|
|
|
+
|
|
|
+// ---
|
|
|
+// Field events
|
|
|
+// ---
|
|
|
+
|
|
|
function onEmailValid(e, data) {
|
|
|
$('#msg').html(data.field + ' is valid');
|
|
|
};
|
|
|
@@ -64,18 +250,15 @@ function onEmailInvalid(e, data) {
|
|
|
|
|
|
describe('event field attribute callback global', function() {
|
|
|
beforeEach(function() {
|
|
|
- var html = [
|
|
|
- '<div class="container">',
|
|
|
- '<form class="form-horizontal" id="eventForm">',
|
|
|
- '<div id="msg"></div>',
|
|
|
- '<div class="form-group">',
|
|
|
- '<input type="text" name="email" data-bv-emailaddress data-bv-onsuccess="onEmailValid" data-bv-onerror="onEmailInvalid" />',
|
|
|
- '</div>',
|
|
|
- '</form>',
|
|
|
- '</div>'
|
|
|
- ].join('\n');
|
|
|
+ $([
|
|
|
+ '<form class="form-horizontal" id="eventForm">',
|
|
|
+ '<div id="msg"></div>',
|
|
|
+ '<div class="form-group">',
|
|
|
+ '<input type="text" name="email" data-bv-emailaddress data-bv-onsuccess="onEmailValid" data-bv-onerror="onEmailInvalid" />',
|
|
|
+ '</div>',
|
|
|
+ '</form>'
|
|
|
+ ].join('\n')).appendTo('body');
|
|
|
|
|
|
- $(html).appendTo('body');
|
|
|
$('#eventForm').bootstrapValidator();
|
|
|
|
|
|
this.bv = $('#eventForm').data('bootstrapValidator');
|
|
|
@@ -83,7 +266,7 @@ describe('event field attribute callback global', function() {
|
|
|
});
|
|
|
|
|
|
afterEach(function() {
|
|
|
- $('#eventForm').bootstrapValidator('destroy').parent().remove();
|
|
|
+ $('#eventForm').bootstrapValidator('destroy').remove();
|
|
|
});
|
|
|
|
|
|
it('call data-bv-onsuccess', function() {
|
|
|
@@ -99,32 +282,17 @@ describe('event field attribute callback global', function() {
|
|
|
});
|
|
|
});
|
|
|
|
|
|
-var My = {
|
|
|
- NameSpace: {
|
|
|
- onEmailValid: function(e, data) {
|
|
|
- $('#msg').html('My.NameSpace.onEmailValid() called, ' + data.field + ' is valid');
|
|
|
- },
|
|
|
-
|
|
|
- onEmailInvalid: function(e, data) {
|
|
|
- $('#msg').html('My.NameSpace.onEmailInvalid() called, ' + data.field + ' is invalid');
|
|
|
- }
|
|
|
- }
|
|
|
-};
|
|
|
-
|
|
|
describe('event field attribute callback namespace', function() {
|
|
|
beforeEach(function() {
|
|
|
- var html = [
|
|
|
- '<div class="container">',
|
|
|
- '<form class="form-horizontal" id="eventForm">',
|
|
|
- '<div id="msg"></div>',
|
|
|
- '<div class="form-group">',
|
|
|
- '<input type="text" name="email" data-bv-emailaddress data-bv-onsuccess="My.NameSpace.onEmailValid" data-bv-onerror="My.NameSpace.onEmailInvalid" />',
|
|
|
- '</div>',
|
|
|
- '</form>',
|
|
|
- '</div>'
|
|
|
- ].join('\n');
|
|
|
+ $([
|
|
|
+ '<form class="form-horizontal" id="eventForm">',
|
|
|
+ '<div id="msg"></div>',
|
|
|
+ '<div class="form-group">',
|
|
|
+ '<input type="text" name="email" data-bv-emailaddress data-bv-onsuccess="My.NameSpace.onEmailValid" data-bv-onerror="My.NameSpace.onEmailInvalid" />',
|
|
|
+ '</div>',
|
|
|
+ '</form>'
|
|
|
+ ].join('\n')).appendTo('body');
|
|
|
|
|
|
- $(html).appendTo('body');
|
|
|
$('#eventForm').bootstrapValidator();
|
|
|
|
|
|
this.bv = $('#eventForm').data('bootstrapValidator');
|
|
|
@@ -132,7 +300,7 @@ describe('event field attribute callback namespace', function() {
|
|
|
});
|
|
|
|
|
|
afterEach(function() {
|
|
|
- $('#eventForm').bootstrapValidator('destroy').parent().remove();
|
|
|
+ $('#eventForm').bootstrapValidator('destroy').remove();
|
|
|
});
|
|
|
|
|
|
it('call data-bv-onsuccess', function() {
|
|
|
@@ -150,18 +318,15 @@ describe('event field attribute callback namespace', function() {
|
|
|
|
|
|
describe('event field trigger', function() {
|
|
|
beforeEach(function() {
|
|
|
- var html = [
|
|
|
- '<div class="container">',
|
|
|
- '<form class="form-horizontal" id="eventForm">',
|
|
|
- '<div id="msg"></div>',
|
|
|
- '<div class="form-group">',
|
|
|
- '<input type="text" name="email" data-bv-emailaddress />',
|
|
|
- '</div>',
|
|
|
- '</form>',
|
|
|
- '</div>'
|
|
|
- ].join('\n');
|
|
|
+ $([
|
|
|
+ '<form class="form-horizontal" id="eventForm">',
|
|
|
+ '<div id="msg"></div>',
|
|
|
+ '<div class="form-group">',
|
|
|
+ '<input type="text" name="email" data-bv-emailaddress />',
|
|
|
+ '</div>',
|
|
|
+ '</form>'
|
|
|
+ ].join('\n')).appendTo('body');
|
|
|
|
|
|
- $(html).appendTo('body');
|
|
|
$('#eventForm')
|
|
|
.bootstrapValidator()
|
|
|
.on('success.field.bv', '[name="email"]', function(e, data) {
|
|
|
@@ -176,7 +341,7 @@ describe('event field trigger', function() {
|
|
|
});
|
|
|
|
|
|
afterEach(function() {
|
|
|
- $('#eventForm').bootstrapValidator('destroy').parent().remove();
|
|
|
+ $('#eventForm').bootstrapValidator('destroy').remove();
|
|
|
});
|
|
|
|
|
|
it('trigger success.field.bv', function() {
|
|
|
@@ -194,18 +359,15 @@ describe('event field trigger', function() {
|
|
|
|
|
|
describe('event field programmatically', function() {
|
|
|
beforeEach(function() {
|
|
|
- var html = [
|
|
|
- '<div class="container">',
|
|
|
- '<form class="form-horizontal" id="eventForm">',
|
|
|
- '<div id="msg"></div>',
|
|
|
- '<div class="form-group">',
|
|
|
- '<input type="text" name="email" data-bv-emailaddress />',
|
|
|
- '</div>',
|
|
|
- '</form>',
|
|
|
- '</div>'
|
|
|
- ].join('\n');
|
|
|
+ $([
|
|
|
+ '<form class="form-horizontal" id="eventForm">',
|
|
|
+ '<div id="msg"></div>',
|
|
|
+ '<div class="form-group">',
|
|
|
+ '<input type="text" name="email" data-bv-emailaddress />',
|
|
|
+ '</div>',
|
|
|
+ '</form>'
|
|
|
+ ].join('\n')).appendTo('body');
|
|
|
|
|
|
- $(html).appendTo('body');
|
|
|
$('#eventForm').bootstrapValidator({
|
|
|
fields: {
|
|
|
email: {
|
|
|
@@ -227,7 +389,7 @@ describe('event field programmatically', function() {
|
|
|
});
|
|
|
|
|
|
afterEach(function() {
|
|
|
- $('#eventForm').bootstrapValidator('destroy').parent().remove();
|
|
|
+ $('#eventForm').bootstrapValidator('destroy').remove();
|
|
|
});
|
|
|
|
|
|
it('call onSuccess()', function() {
|