/*! * BootstrapValidator (http://bootstrapvalidator.com) * The best jQuery plugin to validate form fields. Designed to use with Bootstrap 3 * * @version v0.5.1, built on 2014-08-22 4:55:09 PM * @author https://twitter.com/nghuuphuoc * @copyright (c) 2013 - 2014 Nguyen Huu Phuoc * @license MIT */ (function ($) { const BootstrapValidator = function (form, options) { this.$form = $(form) this.options = $.extend({}, $.fn.bootstrapValidator.DEFAULT_OPTIONS, options) 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' this.STATUS_VALIDATING = 'VALIDATING' this.STATUS_INVALID = 'INVALID' this.STATUS_VALID = 'VALID' // Determine the event that is fired when user change the field value // Most modern browsers supports input event except IE 7, 8. // IE 9 supports input event but the event is still not fired if I press the backspace key. // Get IE version // https://gist.github.com/padolsey/527683/#comment-7595 const ieVersion = (function () { let v = 3; const div = document.createElement('div'); const a = div.all || [] while (div.innerHTML = '', a[0]) {} return v > 4 ? v : !v }()) const el = document.createElement('div') this._changeEvent = (ieVersion === 9 || !('oninput' in el)) ? 'keyup' : 'input' // The flag to indicate that the form is ready to submit when a remote/callback validator returns this._submitIfValid = null // Field elements this._cacheFields = {} this._init() } BootstrapValidator.prototype = { constructor: BootstrapValidator, /** * Init form */ _init: function () { const that = this const options = { excluded: this.$form.attr('data-bv-excluded'), trigger: this.$form.attr('data-bv-trigger'), message: this.$form.attr('data-bv-message'), container: this.$form.attr('data-bv-container'), group: this.$form.attr('data-bv-group'), submitButtons: this.$form.attr('data-bv-submitbuttons'), threshold: this.$form.attr('data-bv-threshold'), live: this.$form.attr('data-bv-live'), onSuccess: this.$form.attr('data-bv-onsuccess'), onError: this.$form.attr('data-bv-onerror'), fields: {}, feedbackIcons: { valid: this.$form.attr('data-bv-feedbackicons-valid'), invalid: this.$form.attr('data-bv-feedbackicons-invalid'), validating: this.$form.attr('data-bv-feedbackicons-validating') }, events: { formInit: this.$form.attr('data-bv-events-form-init'), formError: this.$form.attr('data-bv-events-form-error'), formSuccess: this.$form.attr('data-bv-events-form-success'), fieldAdded: this.$form.attr('data-bv-events-field-added'), fieldRemoved: this.$form.attr('data-bv-events-field-removed'), fieldInit: this.$form.attr('data-bv-events-field-init'), fieldError: this.$form.attr('data-bv-events-field-error'), fieldSuccess: this.$form.attr('data-bv-events-field-success'), fieldStatus: this.$form.attr('data-bv-events-field-status'), validatorError: this.$form.attr('data-bv-events-validator-error'), validatorSuccess: this.$form.attr('data-bv-events-validator-success') } } this.$form // Disable client side validation in HTML 5 .attr('novalidate', 'novalidate') .addClass(this.options.elementClass) // Disable the default submission first .on('submit.bv', function (e) { e.preventDefault() that.validate() }) .on('click.bv', this.options.submitButtons, function () { that.$submitButton = $(this) // The user just click the submit button that._submitIfValid = true }) // Find all fields which have either "name" or "data-bv-field" attribute .find('[name], [data-bv-field]') .each(function () { const $field = $(this) const field = $field.attr('name') || $field.attr('data-bv-field') const opts = that._parseOptions($field) if (opts) { $field.attr('data-bv-field', field) options.fields[field] = $.extend({}, opts, options.fields[field]) } }) 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 = $('