Skip to content

Commit

Permalink
hotfix: delay resolution closes #1041
Browse files Browse the repository at this point in the history
  • Loading branch information
logaretm committed Dec 13, 2017
1 parent eeb0ee6 commit 7b0f84a
Show file tree
Hide file tree
Showing 12 changed files with 82 additions and 30 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
[![codecov](https://codecov.io/gh/baianat/vee-validate/branch/master/graph/badge.svg)](https://codecov.io/gh/baianat/vee-validate)
[![Build Status](https://travis-ci.org/baianat/vee-validate.svg?branch=master)](https://travis-ci.org/baianat/vee-validate)
[![Codacy Badge](https://api.codacy.com/project/badge/Grade/087bd788687c4ccab6650756ce56fa05)](https://www.codacy.com/app/baianat/vee-validate?utm_source=github.com&utm_medium=referral&utm_content=baianat/vee-validate&utm_campaign=Badge_Grade)
[![CDNJS](https://img.shields.io/cdnjs/v/vee-validate.svg)](https://cdnjs.com/libraries/vee-validate/2.0.0-rc.26)
[![CDNJS](https://img.shields.io/cdnjs/v/vee-validate.svg)](https://cdnjs.com/libraries/vee-validate/2.0.0-rc.27)
[![npm](https://img.shields.io/npm/dm/vee-validate.svg)](https://npm-stat.com/charts.html?package=vee-validate)
[![npm](https://img.shields.io/npm/v/vee-validate.svg)](https://www.npmjs.com/package/vee-validate)
[![Average time to resolve an issue](http://isitmaintained.com/badge/resolution/baianat/vee-validate.svg)](http://isitmaintained.com/project/baianat/vee-validate "Average time to resolve an issue")
Expand Down
19 changes: 14 additions & 5 deletions dist/vee-validate.esm.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* vee-validate v2.0.0-rc.26
* vee-validate v2.0.0-rc.27
* (c) 2017 Abdelrahman Awad
* @license MIT
*/
Expand Down Expand Up @@ -1179,7 +1179,13 @@ Generator.resolveDelay = function resolveDelay (el, vnode, options) {
delay = vnode.child.$attrs['data-vv-delay'];
}

return (delay) ? { local: { input: parseInt(delay) }, global: deepParseInt(globalDelay) } : { global: deepParseInt(globalDelay) };
if (!isObject(globalDelay)) {
return deepParseInt(delay || globalDelay);
}

globalDelay.input = delay || 0;

return deepParseInt(globalDelay);
};

/**
Expand Down Expand Up @@ -1377,7 +1383,7 @@ var Field = function Field (el, options) {
this.rules = {};
this._cacheId(options);
options = assign({}, DEFAULT_OPTIONS, options);
this._delay = typeof options.delay === 'number' ? options.delay : (options.delay && options.delay.global); // cache initial delay
this._delay = !isNullOrUndefined(options.delay) ? options.delay : 0; // cache initial delay
this.validity = options.validity;
this.aria = options.aria;
this.flags = createFlags();
Expand Down Expand Up @@ -2916,7 +2922,10 @@ function install (_Vue, options) {
});
}

Validator.localize(locale); // set the locale
if (!i18n) {
Validator.localize(locale); // set the locale
}

Validator.setStrictMode(Config.current.strict);

Vue.mixin(mixin);
Expand Down Expand Up @@ -6934,7 +6943,7 @@ var mapFields = function (fields) {
}, {});
};

var version = '2.0.0-rc.26';
var version = '2.0.0-rc.27';

var rulesPlugin = function (ref) {
var Validator$$1 = ref.Validator;
Expand Down
19 changes: 14 additions & 5 deletions dist/vee-validate.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* vee-validate v2.0.0-rc.26
* vee-validate v2.0.0-rc.27
* (c) 2017 Abdelrahman Awad
* @license MIT
*/
Expand Down Expand Up @@ -5068,7 +5068,13 @@ Generator.resolveDelay = function resolveDelay (el, vnode, options) {
delay = vnode.child.$attrs['data-vv-delay'];
}

return (delay) ? { local: { input: parseInt(delay) }, global: deepParseInt(globalDelay) } : { global: deepParseInt(globalDelay) };
if (!isObject(globalDelay)) {
return deepParseInt(delay || globalDelay);
}

globalDelay.input = delay || 0;

return deepParseInt(globalDelay);
};

/**
Expand Down Expand Up @@ -5266,7 +5272,7 @@ var Field = function Field (el, options) {
this.rules = {};
this._cacheId(options);
options = assign({}, DEFAULT_OPTIONS, options);
this._delay = typeof options.delay === 'number' ? options.delay : (options.delay && options.delay.global); // cache initial delay
this._delay = !isNullOrUndefined(options.delay) ? options.delay : 0; // cache initial delay
this.validity = options.validity;
this.aria = options.aria;
this.flags = createFlags();
Expand Down Expand Up @@ -6805,7 +6811,10 @@ function install (_Vue, options) {
});
}

Validator.localize(locale); // set the locale
if (!i18n) {
Validator.localize(locale); // set the locale
}

Validator.setStrictMode(Config.current.strict);

Vue.mixin(mixin);
Expand Down Expand Up @@ -6948,7 +6957,7 @@ var minimal$1 = {
mapFields: mapFields,
Validator: Validator,
ErrorBag: ErrorBag,
version: '2.0.0-rc.26'
version: '2.0.0-rc.27'
};

// rules plugin definition.
Expand Down
2 changes: 1 addition & 1 deletion dist/vee-validate.min.js

Large diffs are not rendered by default.

19 changes: 14 additions & 5 deletions dist/vee-validate.minimal.esm.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* vee-validate v2.0.0-rc.26
* vee-validate v2.0.0-rc.27
* (c) 2017 Abdelrahman Awad
* @license MIT
*/
Expand Down Expand Up @@ -1179,7 +1179,13 @@ Generator.resolveDelay = function resolveDelay (el, vnode, options) {
delay = vnode.child.$attrs['data-vv-delay'];
}

return (delay) ? { local: { input: parseInt(delay) }, global: deepParseInt(globalDelay) } : { global: deepParseInt(globalDelay) };
if (!isObject(globalDelay)) {
return deepParseInt(delay || globalDelay);
}

globalDelay.input = delay || 0;

return deepParseInt(globalDelay);
};

/**
Expand Down Expand Up @@ -1377,7 +1383,7 @@ var Field = function Field (el, options) {
this.rules = {};
this._cacheId(options);
options = assign({}, DEFAULT_OPTIONS, options);
this._delay = typeof options.delay === 'number' ? options.delay : (options.delay && options.delay.global); // cache initial delay
this._delay = !isNullOrUndefined(options.delay) ? options.delay : 0; // cache initial delay
this.validity = options.validity;
this.aria = options.aria;
this.flags = createFlags();
Expand Down Expand Up @@ -2916,7 +2922,10 @@ function install (_Vue, options) {
});
}

Validator.localize(locale); // set the locale
if (!i18n) {
Validator.localize(locale); // set the locale
}

Validator.setStrictMode(Config.current.strict);

Vue.mixin(mixin);
Expand Down Expand Up @@ -3051,7 +3060,7 @@ var mapFields = function (fields) {
}, {});
};

var version = '2.0.0-rc.26';
var version = '2.0.0-rc.27';

var index_minimal_esm = {
install: install,
Expand Down
19 changes: 14 additions & 5 deletions dist/vee-validate.minimal.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* vee-validate v2.0.0-rc.26
* vee-validate v2.0.0-rc.27
* (c) 2017 Abdelrahman Awad
* @license MIT
*/
Expand Down Expand Up @@ -1185,7 +1185,13 @@ Generator.resolveDelay = function resolveDelay (el, vnode, options) {
delay = vnode.child.$attrs['data-vv-delay'];
}

return (delay) ? { local: { input: parseInt(delay) }, global: deepParseInt(globalDelay) } : { global: deepParseInt(globalDelay) };
if (!isObject(globalDelay)) {
return deepParseInt(delay || globalDelay);
}

globalDelay.input = delay || 0;

return deepParseInt(globalDelay);
};

/**
Expand Down Expand Up @@ -1383,7 +1389,7 @@ var Field = function Field (el, options) {
this.rules = {};
this._cacheId(options);
options = assign({}, DEFAULT_OPTIONS, options);
this._delay = typeof options.delay === 'number' ? options.delay : (options.delay && options.delay.global); // cache initial delay
this._delay = !isNullOrUndefined(options.delay) ? options.delay : 0; // cache initial delay
this.validity = options.validity;
this.aria = options.aria;
this.flags = createFlags();
Expand Down Expand Up @@ -2922,7 +2928,10 @@ function install (_Vue, options) {
});
}

Validator.localize(locale); // set the locale
if (!i18n) {
Validator.localize(locale); // set the locale
}

Validator.setStrictMode(Config.current.strict);

Vue.mixin(mixin);
Expand Down Expand Up @@ -3065,7 +3074,7 @@ var index_minimal = {
mapFields: mapFields,
Validator: Validator,
ErrorBag: ErrorBag,
version: '2.0.0-rc.26'
version: '2.0.0-rc.27'
};

return index_minimal;
Expand Down
2 changes: 1 addition & 1 deletion dist/vee-validate.minimal.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "vee-validate",
"version": "2.0.0-rc.26",
"version": "2.0.0-rc.27",
"description": "Simple Vue.js input validation plugin",
"author": "Abdelrahman Awad <[email protected]>",
"license": "MIT",
Expand Down
3 changes: 2 additions & 1 deletion src/core/field.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ export default class Field {
model: ?string;
value: any;
_alias: ?string;
_delay: number | Object;

constructor (el: HTMLInputElement | null, options: FieldOptions | MapObject = {}) {
this.id = uniqId();
Expand All @@ -83,7 +84,7 @@ export default class Field {
this.rules = {};
this._cacheId(options);
options = assign({}, DEFAULT_OPTIONS, options);
this._delay = typeof options.delay === 'number' ? options.delay : (options.delay && options.delay.global); // cache initial delay
this._delay = !isNullOrUndefined(options.delay) ? options.delay : 0; // cache initial delay
this.validity = options.validity;
this.aria = options.aria;
this.flags = createFlags();
Expand Down
8 changes: 7 additions & 1 deletion src/core/generator.js
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,13 @@ export default class Generator {
delay = vnode.child.$attrs['data-vv-delay'];
}

return (delay) ? { local: { input: parseInt(delay) }, global: deepParseInt(globalDelay) } : { global: deepParseInt(globalDelay) };
if (!isObject(globalDelay)) {
return deepParseInt(delay || globalDelay);
}

globalDelay.input = delay || 0;

return deepParseInt(globalDelay);
}

/**
Expand Down
5 changes: 4 additions & 1 deletion src/install.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,10 @@ function install (_Vue, options = {}) {
});
}

Validator.localize(locale); // set the locale
if (!i18n) {
Validator.localize(locale); // set the locale
}

Validator.setStrictMode(Config.current.strict);

Vue.mixin(mixin);
Expand Down
12 changes: 9 additions & 3 deletions tests/core/generator.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,11 +72,17 @@ test('resolves delay', () => {
`;
const vnode = { child: { $attrs: { 'data-vv-delay': '200' } } };
let el = document.querySelector('#el');
expect(Generator.resolveDelay(el, {})).toEqual(expect.objectContaining({ local: { input: 100 } }));
expect(Generator.resolveDelay(el, {})).toBe(100);

// fills the delay object if the global delay is an object of events.
expect(Generator.resolveDelay(el, {}, { delay: { input: 300, blur: 300 } })).toEqual({
blur: 300,
input: 100
});

el = { getAttribute: () => null };
expect(Generator.resolveDelay(el, vnode)).toEqual(expect.objectContaining({ local: { input: 200 } }));
expect(Generator.resolveDelay(el, {}, { delay: '300' })).toEqual({ global: 300 });
expect(Generator.resolveDelay(el, vnode)).toBe(200);
expect(Generator.resolveDelay(el, {}, { delay: '300' })).toBe(300);
})

test('resolves events', () => {
Expand Down

0 comments on commit 7b0f84a

Please sign in to comment.