vendor/assets/javascripts/formvalidation.js in formvalidation-rails-0.7.0 vs vendor/assets/javascripts/formvalidation.js in formvalidation-rails-0.7.1

- old
+ new

@@ -1,12 +1,12 @@ /*! * FormValidation (http://formvalidation.io) * The best jQuery plugin to validate form fields. Support Bootstrap, Foundation, Pure, SemanticUI, UIKit and custom frameworks * - * @version v0.7.0, built on 2015-08-01 4:57:16 PM + * @version v0.7.1, built on 2016-02-01 12:00:57 AM * @author https://twitter.com/formvalidation - * @copyright (c) 2013 - 2015 Nguyen Huu Phuoc + * @copyright (c) 2013 - 2016 Nguyen Huu Phuoc * @license http://formvalidation.io/license/ */ // Register the namespace window.FormValidation = { AddOn: {}, // Add-ons @@ -123,15 +123,17 @@ }, events: { formInit: this.$form.attr('data-' + ns + '-events-form-init'), formPreValidate: this.$form.attr('data-' + ns + '-events-form-prevalidate'), formError: this.$form.attr('data-' + ns + '-events-form-error'), + formReset: this.$form.attr('data-' + ns + '-events-form-reset'), formSuccess: this.$form.attr('data-' + ns + '-events-form-success'), fieldAdded: this.$form.attr('data-' + ns + '-events-field-added'), fieldRemoved: this.$form.attr('data-' + ns + '-events-field-removed'), fieldInit: this.$form.attr('data-' + ns + '-events-field-init'), fieldError: this.$form.attr('data-' + ns + '-events-field-error'), + fieldReset: this.$form.attr('data-' + ns + '-events-field-reset'), fieldSuccess: this.$form.attr('data-' + ns + '-events-field-success'), fieldStatus: this.$form.attr('data-' + ns + '-events-field-status'), localeChanged: this.$form.attr('data-' + ns + '-events-locale-changed'), validatorError: this.$form.attr('data-' + ns + '-events-validator-error'), validatorSuccess: this.$form.attr('data-' + ns + '-events-validator-success'), @@ -147,10 +149,11 @@ live: this.$form.attr('data-' + ns + '-live'), locale: this.$form.attr('data-' + ns + '-locale'), message: this.$form.attr('data-' + ns + '-message'), onPreValidate: this.$form.attr('data-' + ns + '-onprevalidate'), onError: this.$form.attr('data-' + ns + '-onerror'), + onReset: this.$form.attr('data-' + ns + '-onreset'), onSuccess: this.$form.attr('data-' + ns + '-onsuccess'), row: { selector: this.$form.attr('data-' + ns + '-row-selector') || this.$form.attr('data-' + ns + '-group'), // Support backward valid: this.$form.attr('data-' + ns + '-row-valid'), invalid: this.$form.attr('data-' + ns + '-row-invalid'), @@ -283,10 +286,15 @@ if (this.options.onError) { this.$form.on(this.options.events.formError, function(e) { FormValidation.Helper.call(that.options.onError, [e]); }); } + if (this.options.onReset) { + this.$form.on(this.options.events.formReset, function(e) { + FormValidation.Helper.call(that.options.onReset, [e]); + }); + } }, /** * Init field * @@ -333,10 +341,11 @@ var that = this, total = fields.length, type = fields.attr('type'), updateAll = (total === 1) || ('radio' === type) || ('checkbox' === type), trigger = this._getFieldTrigger(fields.eq(0)), + clazz = this.options.err.clazz.split(' ').join('.'), events = $.map(trigger, function(item) { return item + '.update.' + ns; }).join(' '); for (var i = 0; i < total; i++) { @@ -353,11 +362,11 @@ if (container && container !== 'tooltip' && container !== 'popover') { $message.addClass(this.options.err.clazz); } // Remove all error messages and feedback icons - $message.find('.' + this.options.err.clazz.split(' ').join('.') + '[data-' + ns + '-validator][data-' + ns + '-for="' + field + '"]').remove(); + $message.find('.' + clazz + '[data-' + ns + '-validator][data-' + ns + '-for="' + field + '"]').remove(); $parent.find('i[data-' + ns + '-icon-for="' + field + '"]').remove(); // Whenever the user change the field value, mark it as not validated yet $field.off(events).on(events, function() { that.updateStatus($(this), that.STATUS_NOT_VALIDATED); @@ -432,12 +441,31 @@ this._fixIcon($field, $icon); } } } + // Sort the validators by priority + var sortedByPriority = []; + for (validatorName in validators) { + alias = validators[validatorName].alias || validatorName; + + // Determine the priority + validators[validatorName].priority = parseInt(validators[validatorName].priority + || FormValidation.Validator[alias].priority + || 1, 10); + sortedByPriority.push({ + validator: validatorName, + priority: validators[validatorName].priority + }); + } + sortedByPriority = sortedByPriority.sort(function(a, b) { + return a.priority - b.priority; + }); + // Prepare the events fields + .data(ns + '.validators', sortedByPriority) .on(this.options.events.fieldSuccess, function(e, data) { var onSuccess = that.getOptions(data.field, null, 'onSuccess'); if (onSuccess) { FormValidation.Helper.call(onSuccess, [e, data]); } @@ -446,10 +474,16 @@ var onError = that.getOptions(data.field, null, 'onError'); if (onError) { FormValidation.Helper.call(onError, [e, data]); } }) + .on(this.options.events.fieldReset, function(e, data) { + var onReset = that.getOptions(data.field, null, 'onReset'); + if (onReset) { + FormValidation.Helper.call(onReset, [e, data]); + } + }) .on(this.options.events.fieldStatus, function(e, data) { var onStatus = that.getOptions(data.field, null, 'onStatus'); if (onStatus) { FormValidation.Helper.call(onStatus, [e, data]); } @@ -715,11 +749,13 @@ { // Try to parse the options via attributes validator.html5Attributes = $.extend({}, { message: 'message', onerror: 'onError', + onreset: 'onReset', onsuccess: 'onSuccess', + priority: 'priority', transformer: 'transformer' }, validator.html5Attributes); validators[v] = $.extend({}, html5AttrMap === true ? {} : html5AttrMap, validators[v]); if (validator.alias) { validators[v].alias = validator.alias; @@ -747,10 +783,11 @@ enabled: $field.attr('data-' + ns + '-enabled'), excluded: $field.attr('data-' + ns + '-excluded'), icon: $field.attr('data-' + ns + '-icon') || $field.attr('data-' + ns + '-feedbackicons') || (this.options.fields && this.options.fields[field] ? this.options.fields[field].feedbackIcons : null), // Support backward message: $field.attr('data-' + ns + '-message'), onError: $field.attr('data-' + ns + '-onerror'), + onReset: $field.attr('data-' + ns + '-onreset'), onStatus: $field.attr('data-' + ns + '-onstatus'), onSuccess: $field.attr('data-' + ns + '-onsuccess'), row: $field.attr('data-' + ns + '-row') || $field.attr('data-' + ns + '-group') || (this.options.fields && this.options.fields[field] ? this.options.fields[field].group : null), // Support backward selector: $field.attr('data-' + ns + '-selector'), threshold: $field.attr('data-' + ns + '-threshold'), @@ -1198,16 +1235,17 @@ if (!that._isExcluded($field)) { fields.push($field); } }); - var total = fields.length; + var total = fields.length, + clazz = this.options.err.clazz.split(' ').join('.'); for (var i = 0; i < total; i++) { var $f = fields[i], field = $f.attr('data-' + ns + '-field'), $errors = $f.data(ns + '.messages') - .find('.' + this.options.err.clazz.split(' ').join('.') + '[data-' + ns + '-validator][data-' + ns + '-for="' + field + '"]'); + .find('.' + clazz + '[data-' + ns + '-validator][data-' + ns + '-for="' + field + '"]'); if (this.options.fields && this.options.fields[field] && (this.options.fields[field].enabled === 'false' || this.options.fields[field].enabled === false)) { continue; @@ -1349,12 +1387,11 @@ * @param {String} validator The validator name * @param {String} message The message * @returns {FormValidation.Base} */ updateMessage: function(field, validator, message) { - var that = this, - ns = this._namespace, + var ns = this._namespace, $fields = $([]); switch (typeof field) { case 'object': $fields = field; field = field.attr('data-' + ns + '-field'); @@ -1364,14 +1401,15 @@ break; default: break; } + var clazz = this.options.err.clazz.split(' ').join('.'); $fields.each(function() { $(this) .data(ns + '.messages') - .find('.' + that.options.err.clazz + '[data-' + ns + '-validator="' + validator + '"][data-' + ns + '-for="' + field + '"]').html(message); + .find('.' + clazz + '[data-' + ns + '-validator="' + validator + '"][data-' + ns + '-for="' + field + '"]').html(message); }); return this; }, @@ -1409,21 +1447,22 @@ } var that = this, type = fields.attr('type'), row = this.options.fields[field].row || this.options.row.selector, - total = ('radio' === type || 'checkbox' === type) ? 1 : fields.length; + total = ('radio' === type || 'checkbox' === type) ? 1 : fields.length, + clazz = this.options.err.clazz.split(' ').join('.'); for (var i = 0; i < total; i++) { var $field = fields.eq(i); if (this._isExcluded($field)) { continue; } var $parent = $field.closest(row), $message = $field.data(ns + '.messages'), - $allErrors = $message.find('.' + this.options.err.clazz.split(' ').join('.') + '[data-' + ns + '-validator][data-' + ns + '-for="' + field + '"]'), + $allErrors = $message.find('.' + clazz + '[data-' + ns + '-validator][data-' + ns + '-for="' + field + '"]'), $errors = validatorName ? $allErrors.filter('[data-' + ns + '-validator="' + validatorName + '"]') : $allErrors, $icon = $field.data(ns + '.icon'), // Support backward container = ('function' === typeof (this.options.fields[field].container || this.options.fields[field].err || this.options.err.container)) ? (this.options.fields[field].container || this.options.fields[field].err || this.options.err.container).call(this, $field, this) @@ -1612,12 +1651,16 @@ var $field = fields.eq(i); if (this._isExcluded($field)) { continue; } - var stop = false; - for (validatorName in validators) { + var stop = false, + sortedByPriority = $field.data(ns + '.validators'), + numValidators = sortedByPriority.length; + + for (var j = 0; j < numValidators; j++) { + validatorName = sortedByPriority[j].validator; if ($field.data(ns + '.dfs.' + validatorName)) { $field.data(ns + '.dfs.' + validatorName).reject(); } if (stop) { break; @@ -1786,21 +1829,23 @@ } } } // Remove messages and icons + var clazz = this.options.err.clazz.split(' ').join('.'); for (field in this.options.fields) { fields = this.getFieldElements(field); row = this.options.fields[field].row || this.options.row.selector; for (i = 0; i < fields.length; i++) { $field = fields.eq(i); $field // Remove all error messages .data(ns + '.messages') - .find('.' + this.options.err.clazz.split(' ').join('.') + '[data-' + ns + '-validator][data-' + ns + '-for="' + field + '"]').remove().end() + .find('.' + clazz + '[data-' + ns + '-validator][data-' + ns + '-for="' + field + '"]').remove().end() .end() .removeData(ns + '.messages') + .removeData(ns + '.validators') // Remove feedback classes .closest(row) .removeClass(this.options.row.valid) .removeClass(this.options.row.invalid) .removeClass(this.options.row.feedback) @@ -1979,16 +2024,17 @@ default: $fields = this.$invalidFields; break; } - var filter = validator ? '[data-' + ns + '-validator="' + validator + '"]' : ''; + var filter = validator ? '[data-' + ns + '-validator="' + validator + '"]' : '', + clazz = this.options.err.clazz.split(' ').join('.'); $fields.each(function() { messages = messages.concat( $(this) .data(ns + '.messages') - .find('.' + that.options.err.clazz + '[data-' + ns + '-for="' + $(this).attr('data-' + ns + '-field') + '"][data-' + ns + '-result="' + that.STATUS_INVALID + '"]' + filter) + .find('.' + clazz + '[data-' + ns + '-for="' + $(this).attr('data-' + ns + '-field') + '"][data-' + ns + '-result="' + that.STATUS_INVALID + '"]' + filter) .map(function() { var v = $(this).attr('data-' + ns + '-validator'), f = $(this).attr('data-' + ns + '-for'); return (that.options.fields[f].validators[v].enabled === false) ? '' : $(this).html(); }) @@ -2084,13 +2130,14 @@ break; default: break; } - var total = $fields.length; + var i = 0, + total = $fields.length; if (this.options.fields[field]) { - for (var i = 0; i < total; i++) { + for (i = 0; i < total; i++) { for (var validator in this.options.fields[field].validators) { $fields.eq(i).removeData(ns + '.dfs.' + validator); } } } @@ -2101,10 +2148,19 @@ } // Mark field as not validated yet this.updateStatus(field, this.STATUS_NOT_VALIDATED); + for (i = 0; i < total; i++) { + $fields.eq(i).trigger($.Event(this.options.events.fieldReset), { + fv: this, + field: field, + element: $fields.eq(i), + resetValue: resetValue + }); + } + return this; }, /** * Reset the form @@ -2121,10 +2177,15 @@ this.$submitButton = null; // Enable submit buttons this.disableSubmitButtons(false); + this.$form.trigger($.Event(this.options.events.formReset), { + fv: this, + resetValue: resetValue + }); + return this; }, /** * Revalidate given field @@ -2260,15 +2321,17 @@ events: { // Support backward formInit: 'init.form.fv', formPreValidate: 'prevalidate.form.fv', formError: 'err.form.fv', + formReset: 'rst.form.fv', formSuccess: 'success.form.fv', fieldAdded: 'added.field.fv', fieldRemoved: 'removed.field.fv', fieldInit: 'init.field.fv', fieldError: 'err.field.fv', + fieldReset: 'rst.field.fv', fieldSuccess: 'success.field.fv', fieldStatus: 'status.field.fv', localeChanged: 'changed.locale.fv', validatorError: 'err.validator.fv', validatorSuccess: 'success.validator.fv', @@ -2714,10 +2777,12 @@ } } }); FormValidation.Validator.callback = { + priority: 999, + html5Attributes: { message: 'message', callback: 'callback' }, @@ -3476,34 +3541,33 @@ } } // Validate day, month, and year var valid = FormValidation.Helper.date(year, month, day), - // declare the date, min and max objects min = null, max = null, minOption = options.min, maxOption = options.max; if (minOption) { - if (isNaN(Date.parse(minOption))) { - minOption = validator.getDynamicOption($field, minOption); - } + min = (minOption instanceof Date) + ? minOption + : (this._parseDate(minOption, dateFormat, separator) || + this._parseDate(validator.getDynamicOption($field, minOption), dateFormat, separator)); - min = minOption instanceof Date ? minOption : this._parseDate(minOption, dateFormat, separator); // In order to avoid displaying a date string like "Mon Dec 08 2014 19:14:12 GMT+0000 (WET)" - minOption = minOption instanceof Date ? this._formatDate(minOption, options.format) : minOption; + minOption = this._formatDate(min, options.format); } if (maxOption) { - if (isNaN(Date.parse(maxOption))) { - maxOption = validator.getDynamicOption($field, maxOption); - } + max = (maxOption instanceof Date) + ? maxOption + : (this._parseDate(maxOption, dateFormat, separator) || + this._parseDate(validator.getDynamicOption($field, maxOption), dateFormat, separator)); - max = maxOption instanceof Date ? maxOption : this._parseDate(maxOption, dateFormat, separator); // In order to avoid displaying a date string like "Mon Dec 08 2014 19:14:12 GMT+0000 (WET)" - maxOption = maxOption instanceof Date ? this._formatDate(maxOption, options.format) : maxOption; + maxOption = this._formatDate(max, options.format); } date = new Date(year, month -1, day, hours, minutes, seconds); switch (true) { @@ -3534,37 +3598,51 @@ }, /** * Return a date object after parsing the date string * - * @param {String} date The date string to parse + * @param {Date|String} date The date string to parse * @param {String} format The date format * The format can be: * - date: Consist of DD, MM, YYYY parts which are separated by the separator option * - date and time: * The time can consist of h, m, s parts which are separated by : * @param {String} separator The separator used to separate the date, month, and year * @returns {Date} */ _parseDate: function(date, format, separator) { + if (date instanceof Date) { + return date; + } + if (typeof date !== 'string') { + return null; + } + + // Ensure that the format must consist of year, month and day patterns + var yearIndex = $.inArray('YYYY', format), + monthIndex = $.inArray('MM', format), + dayIndex = $.inArray('DD', format); + if (yearIndex === -1 || monthIndex === -1 || dayIndex === -1) { + return null; + } + var minutes = 0, hours = 0, seconds = 0, sections = date.split(' '), - dateSection = sections[0], - timeSection = (sections.length > 1) ? sections[1] : null; + dateSection = sections[0].split(separator); + if (dateSection.length < 3) { + return null; + } - dateSection = dateSection.split(separator); - var year = dateSection[$.inArray('YYYY', format)], - month = dateSection[$.inArray('MM', format)], - day = dateSection[$.inArray('DD', format)]; - if (timeSection) { - timeSection = timeSection.split(':'); - hours = timeSection.length > 0 ? timeSection[0] : null; - minutes = timeSection.length > 1 ? timeSection[1] : null; - seconds = timeSection.length > 2 ? timeSection[2] : null; + if (sections.length > 1) { + var timeSection = sections[1].split(':'); + hours = timeSection.length > 0 ? timeSection[0] : null; + minutes = timeSection.length > 1 ? timeSection[1] : null; + seconds = timeSection.length > 2 ? timeSection[2] : null; } - return new Date(year, month -1, day, hours, minutes, seconds); + return new Date(dateSection[yearIndex], dateSection[monthIndex] - 1, dateSection[dayIndex], + hours, minutes, seconds); }, /** * Format date * @@ -3678,11 +3756,11 @@ * - field: The name of field that will be used to compare with current one */ init: function(validator, $field, options, validatorName) { var fields = options.field.split(','); for (var i = 0; i < fields.length; i++) { - var compareWith = validator.getFieldElements(fields[i]); + var compareWith = validator.getFieldElements($.trim(fields[i])); validator.onLiveChange(compareWith, 'live_' + validatorName, function() { var status = validator.getStatus($field, validatorName); if (status !== validator.STATUS_NOT_VALIDATED) { validator.revalidateField($field); } @@ -3699,11 +3777,11 @@ * - field: The name of field that will be used to compare with current one */ destroy: function(validator, $field, options, validatorName) { var fields = options.field.split(','); for (var i = 0; i < fields.length; i++) { - var compareWith = validator.getFieldElements(fields[i]); + var compareWith = validator.getFieldElements($.trim(fields[i])); validator.offLiveChange(compareWith, 'live_' + validatorName); } }, /** @@ -3724,11 +3802,11 @@ var fields = options.field.split(','), isValid = true; for (var i = 0; i < fields.length; i++) { - var compareWith = validator.getFieldElements(fields[i]); + var compareWith = validator.getFieldElements($.trim(fields[i])); if (compareWith == null || compareWith.length === 0) { continue; } var compareValue = validator.getFieldValue(compareWith, validatorName); @@ -3833,12 +3911,12 @@ CINCINNATI: ['30', '32', '35', '36', '37', '38', '61'], FRESNO: ['15', '24'], KANSAS_CITY: ['40', '44'], MEMPHIS: ['94', '95'], OGDEN: ['80', '90'], - PHILADELPHIA: ['33', '39', '41', '42', '43', '46', '48', '62', '63', '64', '66', '68', '71', '72', '73', '74', '75', '76', '77', '81', '82', '83', '84', '85', '86', '87', '88', '91', '92', '93', '98', '99'], - INTERNET: ['20', '26', '27', '45', '46'], + PHILADELPHIA: ['33', '39', '41', '42', '43', '48', '62', '63', '64', '66', '68', '71', '72', '73', '74', '75', '76', '77', '81', '82', '83', '84', '85', '86', '87', '88', '91', '92', '93', '98', '99'], + INTERNET: ['20', '26', '27', '45', '46', '47'], SMALL_BUSINESS_ADMINISTRATION: ['31'] }, /** * Validate EIN (Employer Identification Number) which is also known as @@ -4501,10 +4579,11 @@ SE: 'Sweden', SI: 'Slovenia', SK: 'Slovakia', SM: 'San Marino', TH: 'Thailand', + TR: 'Turkey', ZA: 'South Africa' } } } }); @@ -4516,11 +4595,11 @@ }, // Supported country codes COUNTRY_CODES: [ 'BA', 'BG', 'BR', 'CH', 'CL', 'CN', 'CZ', 'DK', 'EE', 'ES', 'FI', 'HR', 'IE', 'IS', 'LT', 'LV', 'ME', 'MK', 'NL', - 'PL', 'RO', 'RS', 'SE', 'SI', 'SK', 'SM', 'TH', 'ZA' + 'PL', 'RO', 'RS', 'SE', 'SI', 'SK', 'SM', 'TH', 'TR', 'ZA' ], /** * Validate identification number in different countries * @@ -5851,10 +5930,30 @@ return (11 - sum % 11) % 10 === parseInt(value.charAt(12), 10); }, /** + * Validate Turkish Identification Number + * + * @see https://en.wikipedia.org/wiki/Turkish_Identification_Number + * @param {String} value The ID + * @returns {Boolean} + */ + _tr: function(value) { + if (value.length !== 11) { + return false; + } + + var sum = 0; + for (var i = 0; i < 10; i++) { + sum += parseInt(value.charAt(i), 10); + } + + return (sum % 10) === parseInt(value.charAt(10), 10); + }, + + /** * Validate South African ID * * @see http://en.wikipedia.org/wiki/National_identification_number#South_Africa * @param {String} value The ID * @returns {Boolean} @@ -6530,11 +6629,11 @@ var value = validator.getFieldValue($field, validatorName); if (value === '') { return true; } - return /^([0-9A-F]{2}[:-]){5}([0-9A-F]{2})$/.test(value); + return /^([0-9A-Fa-f]{2}[:-]){5}([0-9A-Fa-f]{2})$/.test(value) || /^([0-9A-Fa-f]{4}\.){2}([0-9A-Fa-f]{4})$/.test(value); } }; }(jQuery)); ;(function($) { FormValidation.I18n = $.extend(true, FormValidation.I18n || {}, { @@ -6702,15 +6801,24 @@ var value = validator.getFieldValue($field, validatorName); if (value === '') { return true; } + var decimalSeparator = options.separator || options.decimalSeparator || '.', thousandsSeparator = options.thousandsSeparator || ''; - decimalSeparator = (decimalSeparator === '.') ? '\\.' : decimalSeparator; - thousandsSeparator = (thousandsSeparator === '.') ? '\\.' : thousandsSeparator; + // Support preceding zero numbers such as .5, -.5 + if (value.substr(0, 1) === decimalSeparator) { + value = '0' + decimalSeparator + value.substr(1); + } else if (value.substr(0, 2) === '-' + decimalSeparator) { + value = '-0' + decimalSeparator + value.substr(2); + } + + decimalSeparator = (decimalSeparator === '.') ? '\\.' : decimalSeparator; + thousandsSeparator = (thousandsSeparator === '.') ? '\\.' : thousandsSeparator; + var testRegexp = new RegExp('^-?[0-9]{1,3}(' + thousandsSeparator + '[0-9]{3})*(' + decimalSeparator + '[0-9]+)?$'), thousandsReplacer = new RegExp(thousandsSeparator, 'g'); if (!testRegexp.test(value)) { return false; @@ -6936,11 +7044,11 @@ default: // Make sure US phone numbers have 10 digits // May start with 1, +1, or 1-; should discard // Area code may be delimited with (), & sections may be delimited with . or - // http://regexr.com/38mqi - isValid = (/^(?:(1\-?)|(\+1 ?))?\(?(\d{3})[\)\-\.]?(\d{3})[\-\.]?(\d{4})$/).test(value); + isValid = (/^(?:(1\-?)|(\+1 ?))?\(?\d{3}\)?\s?[\-\.]?\d{3}[\-\.]?\d{4}$/).test(value); break; } return { valid: isValid, @@ -6957,10 +7065,12 @@ } } }); FormValidation.Validator.promise = { + priority: 999, + html5Attributes: { message: 'message', promise: 'promise' }, @@ -7027,10 +7137,11 @@ }); FormValidation.Validator.regexp = { html5Attributes: { message: 'message', + flags: 'flags', regexp: 'regexp' }, enableByHtml5: function($field) { var pattern = $field.attr('pattern'); @@ -7048,19 +7159,25 @@ * * @param {FormValidation.Base} validator The validator plugin instance * @param {jQuery} $field Field element * @param {Object} options Consists of the following key: * - regexp: The regular expression you need to check + * - flags: If specified, flags can have any combination of Javascript regular expression flags such as: + * g: global match + * i: ignore case + * m: multiple line * @returns {Boolean} */ validate: function(validator, $field, options, validatorName) { var value = validator.getFieldValue($field, validatorName); if (value === '') { return true; } - var regexp = ('string' === typeof options.regexp) ? new RegExp(options.regexp) : options.regexp; + var regexp = ('string' === typeof options.regexp) + ? (options.flags ? new RegExp(options.regexp, options.flags) : new RegExp(options.regexp)) + : options.regexp; return regexp.test(value); } }; }(jQuery)); ;(function($) { @@ -7071,11 +7188,14 @@ } } }); FormValidation.Validator.remote = { + priority: 1000, + html5Attributes: { + async: 'async', crossdomain: 'crossDomain', data: 'data', datatype: 'dataType', delay: 'delay', message: 'message', @@ -7101,10 +7221,11 @@ * Request a remote server to check the input value * * @param {FormValidation.Base} validator Plugin instance * @param {jQuery} $field Field element * @param {Object} options Can consist of the following keys: + * - async {Boolean} [optional] Indicate the Ajax request will be asynchronous or not. It's true by default * - crossDomain {Boolean} [optional] * - data {Object|Function} [optional]: By default, it will take the value * { * <fieldName>: <fieldValue> * } @@ -7149,9 +7270,10 @@ } data[options.name || name] = value; var ajaxOptions = { + async: options.async === null || options.async === true || options.async === 'true', data: data, dataType: options.dataType || 'json', headers: options.headers || {}, type: options.type || 'GET', url: url