|
1 |
| -/*! nice-validator 1.1.3 |
2 |
| - * (c) 2012-2017 Jony Zhang <[email protected]>, MIT Licensed |
| 1 | +/*! nice-validator 1.1.4 |
| 2 | + * (c) 2012-2018 Jony Zhang <[email protected]>, MIT Licensed |
3 | 3 | * https://github.com/niceue/nice-validator
|
4 | 4 | */
|
5 | 5 | ;(function(factory) {
|
6 |
| - typeof module === "object" && module.exports ? module.exports = factory( require( "jquery" ) ) : |
| 6 | + typeof module === 'object' && module.exports ? module.exports = factory( require( 'jquery' ) ) : |
7 | 7 | typeof define === 'function' && define.amd ? define(['jquery'], factory) :
|
8 | 8 | factory(jQuery);
|
9 | 9 | }(function($, undefined) {
|
10 |
| - "use strict"; |
| 10 | + 'use strict'; |
11 | 11 |
|
12 | 12 | var NS = 'validator',
|
13 | 13 | CLS_NS = '.' + NS,
|
|
286 | 286 | }
|
287 | 287 | options = me._opt = options || {};
|
288 | 288 | dataOpt = attr(element, 'data-'+ NS +'-option');
|
289 |
| - dataOpt = me._dataOpt = dataOpt && dataOpt.charAt(0) === '{' ? (new Function("return " + dataOpt))() : {}; |
| 289 | + dataOpt = me._dataOpt = dataOpt && dataOpt.charAt(0) === '{' ? (new Function('return ' + dataOpt))() : {}; |
290 | 290 | themeOpt = me._themeOpt = themes[ options.theme || dataOpt.theme || defaults.theme ];
|
291 | 291 | opt = me.options = $.extend({}, defaults, fieldDefaults, themeOpt, me.options, options, dataOpt);
|
292 | 292 |
|
|
336 | 336 |
|
337 | 337 | if ( !(me.isAjaxSubmit = !!me.options.valid) ) {
|
338 | 338 | // if there is a "valid.form" event
|
339 |
| - var events = ($._data || $.data)(form, "events"); |
| 339 | + var events = ($._data || $.data)(form, 'events'); |
340 | 340 | me.isAjaxSubmit = issetEvent(events, 'valid', 'form') || issetEvent(events, 'submit', 'form-plugin');
|
341 | 341 | }
|
342 | 342 |
|
343 | 343 | function issetEvent(events, name, namespace) {
|
344 |
| - if ( events && events[name] && |
345 |
| - $.map(events[name], function(e){ |
| 344 | + return !!( |
| 345 | + events && events[name] |
| 346 | + && $.map(events[name], function(e){ |
346 | 347 | return ~e.namespace.indexOf(namespace) ? 1 : null;
|
347 |
| - }).length |
348 |
| - ) { |
349 |
| - return true; |
350 |
| - } |
351 |
| - return false; |
| 348 | + }).length ) |
352 | 349 | }
|
353 | 350 | },
|
354 | 351 |
|
|
464 | 461 | var args = arguments;
|
465 | 462 | args[4] = args[4] || args[5];
|
466 | 463 | field._rules.push({
|
467 |
| - and: args[1] === "&", |
468 |
| - not: args[2] === "!", |
469 |
| - or: args[6] === "|", |
| 464 | + and: args[1] === '&', |
| 465 | + not: args[2] === '!', |
| 466 | + or: args[6] === '|', |
470 | 467 | method: args[3],
|
471 | 468 | params: args[4] ? $.map( args[4].split(', '), trim ) : undefined
|
472 | 469 | });
|
|
781 | 778 | me.showMsg(type)
|
782 | 779 | }
|
783 | 780 | else if ( type === 'tip' ) {
|
784 |
| - me.$el.find(INPUT_SELECTOR +"["+ DATA_TIP +"]", el).each(function(){ |
| 781 | + me.$el.find(INPUT_SELECTOR +'['+ DATA_TIP +']', el).each(function(){ |
785 | 782 | me.showMsg(this, {type: type, msg: msg});
|
786 | 783 | });
|
787 | 784 | }
|
|
897 | 894 | rule = field._rules[field._i];
|
898 | 895 | if (rule.not) {
|
899 | 896 | msg = undefined;
|
900 |
| - isValid = method === "required" || !isValid; |
| 897 | + isValid = method === 'required' || !isValid; |
901 | 898 | }
|
902 | 899 | if (rule.or) {
|
903 | 900 | if (isValid) {
|
|
1002 | 999 | field._r = method;
|
1003 | 1000 |
|
1004 | 1001 | if (old && !field.must && !rule.must && rule.result !== undefined &&
|
1005 |
| - old.ruleName === method && old.id === el.id && |
| 1002 | + old.ruleName === method && old.id === el.id && |
1006 | 1003 | field.value && old.value === field.value )
|
1007 | 1004 | {
|
1008 | 1005 | // get result from cache
|
|
1415 | 1412 | },
|
1416 | 1413 | getValue: function() {
|
1417 | 1414 | var elem = this.element;
|
1418 |
| - if (elem.type === "number" && elem.validity && elem.validity.badInput) { |
| 1415 | + if (elem.type === 'number' && elem.validity && elem.validity.badInput) { |
1419 | 1416 | return 'NaN';
|
1420 | 1417 | }
|
1421 | 1418 | return $(elem)[this._valHook()]();
|
|
1523 | 1520 | var k, that = context ? context === true ? this : context : Rules.prototype;
|
1524 | 1521 |
|
1525 | 1522 | for (k in obj) {
|
1526 |
| - if (_checkRuleName(k)) |
| 1523 | + if (_checkRuleName(k)) { |
1527 | 1524 | that[k] = _getRule(obj[k]);
|
| 1525 | + } |
1528 | 1526 | }
|
1529 | 1527 | }
|
1530 | 1528 |
|
|
1598 | 1596 | function _getDataRule(el, method) {
|
1599 | 1597 | var fn = trim(attr(el, DATA_RULE + '-' + method));
|
1600 | 1598 |
|
1601 |
| - if ( fn && (fn = new Function("return " + fn)()) ) { |
| 1599 | + if ( fn && (fn = new Function('return ' + fn)()) ) { |
1602 | 1600 | return _getRule(fn);
|
1603 | 1601 | }
|
1604 | 1602 | }
|
|
1641 | 1639 |
|
1642 | 1640 | // Translate field key to jQuery selector.
|
1643 | 1641 | function _key2selector(key) {
|
1644 |
| - var isID = key.charAt(0) === "#"; |
1645 |
| - key = key.replace(/([:.{(|)}/\[\]])/g, "\\$1"); |
| 1642 | + var isID = key.charAt(0) === '#'; |
| 1643 | + key = key.replace(/([:.{(|)}/\[\]])/g, '\\$1'); |
1646 | 1644 | return isID ? key : '[name="'+ key +'"]:first';
|
1647 | 1645 | }
|
1648 | 1646 |
|
|
1683 | 1681 | });
|
1684 | 1682 |
|
1685 | 1683 | new Messages({
|
1686 |
| - fallback: "This field is not valid.", |
| 1684 | + fallback: 'This field is not valid.', |
1687 | 1685 | loading: 'Validating...'
|
1688 | 1686 | });
|
1689 | 1687 |
|
|
1696 | 1694 | *
|
1697 | 1695 | * @example:
|
1698 | 1696 | required
|
| 1697 | + required(jqSelector) |
1699 | 1698 | required(anotherRule)
|
1700 | 1699 | required(not, -1)
|
1701 | 1700 | required(from, .contact)
|
|
1836 | 1835 | }
|
1837 | 1836 |
|
1838 | 1837 | // If both fields are blank
|
1839 |
| - if (!me.required && a === "" && b === "") { |
| 1838 | + if (!me.required && a === '' && b === '') { |
1840 | 1839 | return null;
|
1841 | 1840 | }
|
1842 | 1841 |
|
|
1852 | 1851 | }
|
1853 | 1852 |
|
1854 | 1853 | // If the compared field is incorrect, we only ensure that this field is correct.
|
1855 |
| - if (type !== "eq" && !isNaN(+a) && isNaN(+b)) { |
| 1854 | + if (type !== 'eq' && !isNaN(+a) && isNaN(+b)) { |
1856 | 1855 | return true;
|
1857 | 1856 | }
|
1858 | 1857 |
|
|
1873 | 1872 |
|
1874 | 1873 | return isValid || (
|
1875 | 1874 | isObject(me.messages.match)
|
1876 |
| - && me.messages.match[type].replace( '{1}', me._getDisplay( element, field2.display || key ) ) |
| 1875 | + && me.messages.match[type].replace( '{1}', me._getDisplay( elem2, field2.display || key ) ) |
1877 | 1876 | );
|
1878 | 1877 | },
|
1879 | 1878 |
|
|
1957 | 1956 | By GET: remote(get:path/to/server, name1, name2, ...);
|
1958 | 1957 | Name proxy: remote(path/to/server, name1, proxyname2:name2, proxyname3:#id3, ...)
|
1959 | 1958 | Query String remote(path/to/server, foo=1&bar=2, name1, name2, ...)
|
| 1959 | + CORS remote(cors:path/to/server) |
| 1960 | + JSONP remote(jsonp:path/to/server) |
1960 | 1961 | */
|
1961 | 1962 | remote: function(element, params) {
|
1962 | 1963 | if (!params) return;
|
|
2017 | 2018 | */
|
2018 | 2019 | filter: function(element, params) {
|
2019 | 2020 | var value = this.value,
|
2020 |
| - temp = value.replace( params ? (new RegExp("[" + params[0] + "]", "gm")) : rUnsafe, '' ); |
| 2021 | + temp = value.replace( params ? (new RegExp('[' + params[0] + ']', 'gm')) : rUnsafe, '' ); |
2021 | 2022 | if (temp !== value) this.setValue(temp);
|
2022 | 2023 | }
|
2023 | 2024 | });
|
|
0 commit comments