Skip to content

Commit

Permalink
#665: The submitButtons option doesn't work correctly
Browse files Browse the repository at this point in the history
  • Loading branch information
nghuuphuoc committed Aug 16, 2014
1 parent 5a1803e commit f3ac2e3
Show file tree
Hide file tree
Showing 5 changed files with 57 additions and 12 deletions.
5 changes: 3 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ __New features__
* [#510](https://github.com/nghuuphuoc/bootstrapvalidator/pull/510), [#646](https://github.com/nghuuphuoc/bootstrapvalidator/pull/646): Add French [phone number](http://bootstrapvalidator.com/validators/phone/) validator, thanks to [@dlucazeau](https://github.com/dlucazeau)
* [#536](https://github.com/nghuuphuoc/bootstrapvalidator/pull/536): Add Spanish [phone number](http://bootstrapvalidator.com/validators/phone/) validator, thanks to [@vadail](https://github.com/vadail)
* [#519](https://github.com/nghuuphuoc/bootstrapvalidator/pull/519): Add Iceland [VAT](http://bootstrapvalidator.com/validators/vat/) number validator, thanks to [@evilchili](https://github.com/evilchili)
* [#621](https://github.com/nghuuphuoc/bootstrapvalidator/pull/621): Add Pakistan [phone number](http://bootstrapvalidator.com/validators/phone/) validator, thanks to [@abuzer](https://github.com/abuzer)
* [#620](https://github.com/nghuuphuoc/bootstrapvalidator/issues/620), [#621](https://github.com/nghuuphuoc/bootstrapvalidator/pull/621): Add Pakistan [phone number](http://bootstrapvalidator.com/validators/phone/) validator, thanks to [@abuzer](https://github.com/abuzer)
* [#630](https://github.com/nghuuphuoc/bootstrapvalidator/issues/630), [#640](https://github.com/nghuuphuoc/bootstrapvalidator/pull/640): Add event name options to avoid window.onerror being invoked by jQuery, thanks to [@roryprimrose](https://github.com/roryprimrose). Thanks to [@stephengreentree](https://github.com/stephengreentree) for creating the test suite ([#657](https://github.com/nghuuphuoc/bootstrapvalidator/pull/657))
* [#637](https://github.com/nghuuphuoc/bootstrapvalidator/pull/637): Add South African [VAT](http://bootstrapvalidator.com/validators/vat/) number validator, thanks to [@evilchili](https://github.com/evilchili)
* [#638](https://github.com/nghuuphuoc/bootstrapvalidator/pull/638), [#647](https://github.com/nghuuphuoc/bootstrapvalidator/pull/647): Add Brazilian [phone number](http://bootstrapvalidator.com/validators/phone/) and [postal code](http://bootstrapvalidator.com/validators/zipCode/) validator, thanks to [@fhferreira](https://github.com/fhferreira)
Expand All @@ -28,7 +28,8 @@ __Improvements__
__Bug Fixes__

* [#550](https://github.com/nghuuphuoc/bootstrapvalidator/issues/550), [#551](https://github.com/nghuuphuoc/bootstrapvalidator/pull/551): Cannot validate against both ipv4 and ipv6 at the same time, thanks to [@beeglebug](https://github.com/beeglebug)
* [#672](https://github.com/nghuuphuoc/bootstrapvalidator/issues/672): The zipCode validator throw an exception when passing not supported country code
* [#665](https://github.com/nghuuphuoc/bootstrapvalidator/issues/665): The [submitButtons](http://bootstrapvalidator.com/settings/#form-submit-buttons) option doesn't work correctly
* [#672](https://github.com/nghuuphuoc/bootstrapvalidator/issues/672): The [zipCode](http://bootstrapvalidator.com/validators/zipCode/) validator throw an exception when passing not supported country code

__Language Packages__

Expand Down
2 changes: 1 addition & 1 deletion dist/css/bootstrapValidator.min.css
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* BootstrapValidator (http://bootstrapvalidator.com)
* The best jQuery plugin to validate form fields. Designed to use with Bootstrap 3
*
* @version v0.5.1-dev, built on 2014-08-16 10:50:13 AM
* @version v0.5.1-dev, built on 2014-08-16 5:21:21 PM
* @author https://twitter.com/nghuuphuoc
* @copyright (c) 2013 - 2014 Nguyen Huu Phuoc
* @license MIT
Expand Down
30 changes: 26 additions & 4 deletions dist/js/bootstrapValidator.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* BootstrapValidator (http://bootstrapvalidator.com)
* The best jQuery plugin to validate form fields. Designed to use with Bootstrap 3
*
* @version v0.5.1-dev, built on 2014-08-16 10:50:13 AM
* @version v0.5.1-dev, built on 2014-08-16 5:21:21 PM
* @author https://twitter.com/nghuuphuoc
* @copyright (c) 2013 - 2014 Nguyen Huu Phuoc
* @license MIT
Expand All @@ -14,6 +14,7 @@

this.$invalidFields = $([]); // Array of invalid fields
this.$submitButton = null; // The submit button which is clicked to submit form
this.$hiddenButton = null;

// Validating status
this.STATUS_NOT_VALIDATED = 'NOT_VALIDATED';
Expand Down Expand Up @@ -111,6 +112,26 @@
});

this.options = $.extend(true, this.options, options);

// When pressing Enter on any field in the form, the first submit button will do its job.
// The form then will be submitted.
// I create a first hidden submit button
this.$hiddenButton = $('<button/>')
.attr('type', 'submit')
.prependTo(this.$form)
.addClass('bv-hidden-submit')
.css({ display: 'none', width: 0, height: 0 });

this.$form
.on('click.bv', '[type="submit"]', function(e) {
// Don't perform validation when clicking on the submit button/input
// which aren't defined by the 'submitButtons' option
var $button = $(e.target).eq(0);
if (that.options.submitButtons && !$button.is(that.options.submitButtons) && !$button.is(that.$hiddenButton)) {
that.$form.off('submit.bv').submit();
}
});

for (var field in this.options.fields) {
this._initField(field);
}
Expand Down Expand Up @@ -1544,15 +1565,16 @@
}
}

// Enable submit buttons
this.disableSubmitButtons(false);
this.disableSubmitButtons(false); // Enable submit buttons
this.$hiddenButton.remove(); // Remove the hidden button

this.$form
.removeClass(this.options.elementClass)
.off('.bv')
.removeData('bootstrapValidator')
// Remove generated hidden elements
.find('[data-bv-submit-hidden]').remove();
.find('[data-bv-submit-hidden]').remove().end()
.find('[type="submit"]').off('click.bv');
}
};

Expand Down
4 changes: 2 additions & 2 deletions dist/js/bootstrapValidator.min.js

Large diffs are not rendered by default.

28 changes: 25 additions & 3 deletions src/js/bootstrapValidator.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

this.$invalidFields = $([]); // Array of invalid fields
this.$submitButton = null; // The submit button which is clicked to submit form
this.$hiddenButton = null;

// Validating status
this.STATUS_NOT_VALIDATED = 'NOT_VALIDATED';
Expand Down Expand Up @@ -110,6 +111,26 @@
});

this.options = $.extend(true, this.options, options);

// When pressing Enter on any field in the form, the first submit button will do its job.
// The form then will be submitted.
// I create a first hidden submit button
this.$hiddenButton = $('<button/>')
.attr('type', 'submit')
.prependTo(this.$form)
.addClass('bv-hidden-submit')
.css({ display: 'none', width: 0, height: 0 });

this.$form
.on('click.bv', '[type="submit"]', function(e) {
// Don't perform validation when clicking on the submit button/input
// which aren't defined by the 'submitButtons' option
var $button = $(e.target).eq(0);
if (that.options.submitButtons && !$button.is(that.options.submitButtons) && !$button.is(that.$hiddenButton)) {
that.$form.off('submit.bv').submit();
}
});

for (var field in this.options.fields) {
this._initField(field);
}
Expand Down Expand Up @@ -1543,15 +1564,16 @@
}
}

// Enable submit buttons
this.disableSubmitButtons(false);
this.disableSubmitButtons(false); // Enable submit buttons
this.$hiddenButton.remove(); // Remove the hidden button

this.$form
.removeClass(this.options.elementClass)
.off('.bv')
.removeData('bootstrapValidator')
// Remove generated hidden elements
.find('[data-bv-submit-hidden]').remove();
.find('[data-bv-submit-hidden]').remove().end()
.find('[type="submit"]').off('click.bv');
}
};

Expand Down

0 comments on commit f3ac2e3

Please sign in to comment.