vee-validate 2.1.2 → 2.1.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,5 +1,5 @@
1
1
  /**
2
- * vee-validate v2.1.2
2
+ * vee-validate v2.1.3
3
3
  * (c) 2018 Abdelrahman Awad
4
4
  * @license MIT
5
5
  */
@@ -1189,130 +1189,148 @@ ErrorBag.prototype._match = function _match (selector) {
1189
1189
  }, {});
1190
1190
  };
1191
1191
 
1192
- // VNode Utils
1193
-
1194
- // Gets the model object on the vnode.
1195
- function findModel (vnode) {
1196
- if (!vnode.data) {
1197
- return null;
1198
- }
1199
-
1200
- // Component Model
1201
- if (vnode.data.model) {
1202
- return vnode.data.model;
1203
- }
1204
-
1205
- return !!(vnode.data.directives) && find(vnode.data.directives, function (d) { return d.name === 'model'; });
1206
- }
1207
-
1208
- function extractVNodes (vnode) {
1209
- if (findModel(vnode)) {
1210
- return [vnode];
1211
- }
1212
-
1213
- var children = Array.isArray(vnode) ? vnode : vnode.children;
1214
- if (!Array.isArray(children)) {
1215
- return [];
1216
- }
1217
-
1218
- return children.reduce(function (nodes, node) {
1219
- var candidates = extractVNodes(node);
1220
- if (candidates.length) {
1221
- nodes.push.apply(nodes, candidates);
1222
- }
1223
-
1224
- return nodes;
1225
- }, []);
1226
- }
1227
-
1228
- // Resolves v-model config if exists.
1229
- function findModelConfig (vnode) {
1230
- if (!vnode.componentOptions) { return null; }
1231
-
1232
- return vnode.componentOptions.Ctor.options.model;
1233
- }
1234
- // Adds a listener to vnode listener object.
1235
- function mergeVNodeListeners (obj, eventName, handler) {
1236
- // Has a single listener.
1237
- if (isCallable(obj[eventName])) {
1238
- var prevHandler = obj[eventName];
1239
- obj[eventName] = [prevHandler];
1240
- }
1241
-
1242
- // has other listeners.
1243
- if (Array.isArray(obj[eventName])) {
1244
- obj[eventName].push(handler);
1245
- return;
1246
- }
1247
-
1248
- // no listener at all.
1249
- if (isNullOrUndefined(obj[eventName])) {
1250
- obj[eventName] = [handler];
1251
- }
1252
- }
1253
-
1254
- // Adds a listener to a native HTML vnode.
1255
- function addNativeNodeListener (node, eventName, handler) {
1256
- if (isNullOrUndefined(node.data.on)) {
1257
- node.data.on = {};
1258
- }
1259
-
1260
- mergeVNodeListeners(node.data.on, eventName, handler);
1261
- }
1262
-
1263
- // Adds a listener to a Vue component vnode.
1264
- function addComponentNodeListener (node, eventName, handler) {
1265
- /* istanbul ignore next */
1266
- if (!node.componentOptions.listeners) {
1267
- node.componentOptions.listeners = {};
1268
- }
1269
-
1270
- mergeVNodeListeners(node.componentOptions.listeners, eventName, handler);
1271
- }
1272
- function addVNodeListener (vnode, eventName, handler) {
1273
- if (vnode.componentOptions) {
1274
- addComponentNodeListener(vnode, eventName, handler);
1275
- }
1276
-
1277
- addNativeNodeListener(vnode, eventName, handler);
1278
- }
1279
- // Determines if `change` should be used over `input` for listeners.
1280
- function getInputEventName (vnode, model) {
1281
- // Is a component.
1282
- if (vnode.componentOptions) {
1192
+ // VNode Utils
1193
+
1194
+ // Gets the model object on the vnode.
1195
+ function findModel (vnode) {
1196
+ if (!vnode.data) {
1197
+ return null;
1198
+ }
1199
+
1200
+ // Component Model
1201
+ if (vnode.data.model) {
1202
+ return vnode.data.model;
1203
+ }
1204
+
1205
+ return !!(vnode.data.directives) && find(vnode.data.directives, function (d) { return d.name === 'model'; });
1206
+ }
1207
+
1208
+ function extractVNodes (vnode) {
1209
+ if (findModel(vnode)) {
1210
+ return [vnode];
1211
+ }
1212
+
1213
+ var children = Array.isArray(vnode) ? vnode : vnode.children;
1214
+ if (!Array.isArray(children)) {
1215
+ return [];
1216
+ }
1217
+
1218
+ return children.reduce(function (nodes, node) {
1219
+ var candidates = extractVNodes(node);
1220
+ if (candidates.length) {
1221
+ nodes.push.apply(nodes, candidates);
1222
+ }
1223
+
1224
+ return nodes;
1225
+ }, []);
1226
+ }
1227
+
1228
+ // Resolves v-model config if exists.
1229
+ function findModelConfig (vnode) {
1230
+ if (!vnode.componentOptions) { return null; }
1231
+
1232
+ return vnode.componentOptions.Ctor.options.model;
1233
+ }
1234
+ // Adds a listener to vnode listener object.
1235
+ function mergeVNodeListeners (obj, eventName, handler) {
1236
+ // Has a single listener.
1237
+ if (isCallable(obj[eventName])) {
1238
+ var prevHandler = obj[eventName];
1239
+ obj[eventName] = [prevHandler];
1240
+ }
1241
+
1242
+ // has other listeners.
1243
+ if (Array.isArray(obj[eventName])) {
1244
+ obj[eventName].push(handler);
1245
+ return;
1246
+ }
1247
+
1248
+ // no listener at all.
1249
+ if (isNullOrUndefined(obj[eventName])) {
1250
+ obj[eventName] = [handler];
1251
+ }
1252
+ }
1253
+
1254
+ // Adds a listener to a native HTML vnode.
1255
+ function addNativeNodeListener (node, eventName, handler) {
1256
+ if (isNullOrUndefined(node.data.on)) {
1257
+ node.data.on = {};
1258
+ }
1259
+
1260
+ mergeVNodeListeners(node.data.on, eventName, handler);
1261
+ }
1262
+
1263
+ // Adds a listener to a Vue component vnode.
1264
+ function addComponentNodeListener (node, eventName, handler) {
1265
+ /* istanbul ignore next */
1266
+ if (!node.componentOptions.listeners) {
1267
+ node.componentOptions.listeners = {};
1268
+ }
1269
+
1270
+ mergeVNodeListeners(node.componentOptions.listeners, eventName, handler);
1271
+ }
1272
+ function addVNodeListener (vnode, eventName, handler) {
1273
+ if (vnode.componentOptions) {
1274
+ addComponentNodeListener(vnode, eventName, handler);
1275
+ }
1276
+
1277
+ addNativeNodeListener(vnode, eventName, handler);
1278
+ }
1279
+ // Determines if `change` should be used over `input` for listeners.
1280
+ function getInputEventName (vnode, model) {
1281
+ // Is a component.
1282
+ if (vnode.componentOptions) {
1283
1283
  var ref = findModelConfig(vnode) || { event: 'input' };
1284
- var event = ref.event;
1285
-
1286
- return event;
1287
- }
1288
-
1289
- // Lazy Models typically use change event
1290
- if (model && model.modifiers && model.modifiers.lazy) {
1291
- return 'change';
1292
- }
1293
-
1294
- // is a textual-type input.
1295
- if (vnode.data.attrs && isTextInput({ type: vnode.data.attrs.type || 'text' })) {
1296
- return 'input';
1297
- }
1298
-
1299
- return 'change';
1300
- }
1301
-
1302
- function normalizeSlots (slots, ctx) {
1303
- return Object.keys(slots).reduce(function (arr, key) {
1304
- slots[key].forEach(function (vnode) {
1305
- if (!vnode.context) {
1306
- slots[key].context = ctx;
1307
- if (!vnode.data) {
1308
- vnode.data = {};
1309
- }
1310
- vnode.data.slot = key;
1311
- }
1312
- });
1313
-
1314
- return arr.concat(slots[key]);
1315
- }, []);
1284
+ var event = ref.event;
1285
+
1286
+ return event;
1287
+ }
1288
+
1289
+ // Lazy Models typically use change event
1290
+ if (model && model.modifiers && model.modifiers.lazy) {
1291
+ return 'change';
1292
+ }
1293
+
1294
+ // is a textual-type input.
1295
+ if (vnode.data.attrs && isTextInput({ type: vnode.data.attrs.type || 'text' })) {
1296
+ return 'input';
1297
+ }
1298
+
1299
+ return 'change';
1300
+ }
1301
+
1302
+ function normalizeSlots (slots, ctx) {
1303
+ return Object.keys(slots).reduce(function (arr, key) {
1304
+ slots[key].forEach(function (vnode) {
1305
+ if (!vnode.context) {
1306
+ slots[key].context = ctx;
1307
+ if (!vnode.data) {
1308
+ vnode.data = {};
1309
+ }
1310
+ vnode.data.slot = key;
1311
+ }
1312
+ });
1313
+
1314
+ return arr.concat(slots[key]);
1315
+ }, []);
1316
+ }
1317
+
1318
+ function createRenderless (h, vnode) {
1319
+ // a single-root slot yay!
1320
+ if (!Array.isArray(vnode)) {
1321
+ return vnode;
1322
+ }
1323
+
1324
+ if (vnode.length === 1) {
1325
+ return vnode[0];
1326
+ }
1327
+
1328
+ if (process.env.NODE_ENV !== 'production') {
1329
+ warn('Your slot should have one root element. Rendering a span as the root.');
1330
+ }
1331
+
1332
+ // Renders a multi-root node, should throw a Vue error.
1333
+ return vnode;
1316
1334
  }
1317
1335
 
1318
1336
  /**
@@ -1660,7 +1678,7 @@ Object.defineProperties( RuleContainer, staticAccessors );
1660
1678
  //
1661
1679
 
1662
1680
  var isEvent = function (evt) {
1663
- return (isCallable(Event) && evt instanceof Event) || (evt && evt.srcElement);
1681
+ return (typeof Event !== 'undefined' && isCallable(Event) && evt instanceof Event) || (evt && evt.srcElement);
1664
1682
  };
1665
1683
 
1666
1684
  var normalizeEvents = function (evts) {
@@ -2926,7 +2944,9 @@ Validator.localize = function localize (lang, dictionary) {
2926
2944
  /**
2927
2945
  * Registers a field to be validated.
2928
2946
  */
2929
- Validator.prototype.attach = function attach (fieldOpts) {
2947
+ Validator.prototype.attach = function attach (fieldOpts) {
2948
+ var this$1 = this;
2949
+
2930
2950
  // fixes initial value detection with v-model and select elements.
2931
2951
  var value = fieldOpts.initialValue;
2932
2952
  var field = new Field(fieldOpts);
@@ -2934,7 +2954,7 @@ Validator.prototype.attach = function attach (fieldOpts) {
2934
2954
 
2935
2955
  // validate the field initially
2936
2956
  if (field.immediate) {
2937
- this.validate(("#" + (field.id)), value || field.value, { vmId: fieldOpts.vmId });
2957
+ VeeValidate.instance._vm.$nextTick(function () { return this$1.validate(("#" + (field.id)), value || field.value, { vmId: fieldOpts.vmId }); });
2938
2958
  } else {
2939
2959
  this._validate(field, value || field.value, { initial: true }).then(function (result) {
2940
2960
  field.flags.valid = result.valid;
@@ -3715,7 +3735,7 @@ function onRenderUpdate (model) {
3715
3735
  });
3716
3736
  };
3717
3737
 
3718
- this.syncValue(model.value);
3738
+ this.value = model.value;
3719
3739
  this.validate().then(this.immediate || shouldRevalidate ? this.applyResult : silentHandler);
3720
3740
  }
3721
3741
 
@@ -3779,11 +3799,16 @@ function createValuesLookup (ctx) {
3779
3799
  var providers = ctx.$_veeObserver.refs;
3780
3800
 
3781
3801
  return ctx.fieldDeps.reduce(function (acc, depName) {
3782
- if (providers[depName]) {
3783
- acc[depName] = providers[depName].value;
3784
- var unwatch = providers[depName].$watch('value', function () {
3802
+ if (!providers[depName]) {
3803
+ return acc;
3804
+ }
3805
+
3806
+ acc[depName] = providers[depName].value;
3807
+ var watcherName = "$__" + depName;
3808
+ if (!isCallable(ctx[watcherName])) {
3809
+ ctx[watcherName] = providers[depName].$watch('value', function () {
3785
3810
  ctx.validate(ctx.value).then(ctx.applyResult);
3786
- unwatch();
3811
+ ctx[watcherName]();
3787
3812
  });
3788
3813
  }
3789
3814
 
@@ -3861,10 +3886,6 @@ var ValidationProvider = {
3861
3886
  type: Boolean,
3862
3887
  default: false
3863
3888
  },
3864
- tag: {
3865
- type: String,
3866
- default: 'span'
3867
- },
3868
3889
  bails: {
3869
3890
  type: Boolean,
3870
3891
  default: function () { return VeeValidate.config.fastExit; }
@@ -4003,22 +4024,19 @@ var ValidationProvider = {
4003
4024
  var slot = this.$scopedSlots.default;
4004
4025
  if (!isCallable(slot)) {
4005
4026
  if (process.env.NODE_ENV !== 'production') {
4006
- warn('Did you forget to add a scoped slot to the ValidationProvider?');
4027
+ warn('ValidationProvider expects a scoped slot. Did you forget to add "slot-scope" to your slot?');
4007
4028
  }
4008
4029
 
4009
- slot = function () { return normalizeSlots(this$1.$slots, this$1.$vnode.context); };
4030
+ return createRenderless(h, this.$slots.default);
4010
4031
  }
4011
4032
 
4012
4033
  var nodes = slot(ctx);
4013
4034
  // Handle single-root slot.
4014
- nodes = Array.isArray(nodes) ? nodes : [nodes];
4015
- extractVNodes({ children: nodes }).forEach(function (input) {
4035
+ extractVNodes(nodes).forEach(function (input) {
4016
4036
  addListeners.call(this$1, input);
4017
4037
  });
4018
4038
 
4019
- return h(this.tag, {
4020
- attrs: this.$attrs
4021
- }, nodes);
4039
+ return createRenderless(h, nodes);
4022
4040
  },
4023
4041
  beforeDestroy: function beforeDestroy () {
4024
4042
  // cleanup reference.
@@ -4026,99 +4044,90 @@ var ValidationProvider = {
4026
4044
  }
4027
4045
  };
4028
4046
 
4029
- var flagMergingStrategy = {
4030
- pristine: 'every',
4031
- dirty: 'some',
4032
- touched: 'some',
4033
- untouched: 'every',
4034
- valid: 'every',
4035
- invalid: 'some',
4036
- pending: 'some',
4037
- validated: 'every'
4038
- };
4039
-
4040
- function mergeFlags (lhs, rhs, strategy) {
4041
- var stratName = flagMergingStrategy[strategy];
4042
-
4043
- return [lhs, rhs][stratName](function (f) { return f; });
4044
- }
4045
-
4046
- var ValidationObserver = {
4047
- name: 'ValidationObserver',
4048
- provide: function provide () {
4049
- return {
4050
- $_veeObserver: this
4051
- };
4052
- },
4053
- props: {
4054
- tag: {
4055
- type: String,
4056
- default: 'span'
4057
- }
4058
- },
4059
- data: function () { return ({
4060
- refs: {}
4061
- }); },
4062
- methods: {
4047
+ var flagMergingStrategy = {
4048
+ pristine: 'every',
4049
+ dirty: 'some',
4050
+ touched: 'some',
4051
+ untouched: 'every',
4052
+ valid: 'every',
4053
+ invalid: 'some',
4054
+ pending: 'some',
4055
+ validated: 'every'
4056
+ };
4057
+
4058
+ function mergeFlags (lhs, rhs, strategy) {
4059
+ var stratName = flagMergingStrategy[strategy];
4060
+
4061
+ return [lhs, rhs][stratName](function (f) { return f; });
4062
+ }
4063
+
4064
+ var ValidationObserver = {
4065
+ name: 'ValidationObserver',
4066
+ provide: function provide () {
4067
+ return {
4068
+ $_veeObserver: this
4069
+ };
4070
+ },
4071
+ data: function () { return ({
4072
+ refs: {}
4073
+ }); },
4074
+ methods: {
4063
4075
  $subscribe: function $subscribe (provider) {
4064
4076
  var obj;
4065
-
4066
- this.refs = Object.assign({}, this.refs, ( obj = {}, obj[provider.vid] = provider, obj ));
4067
- },
4077
+
4078
+ this.refs = Object.assign({}, this.refs, ( obj = {}, obj[provider.vid] = provider, obj ));
4079
+ },
4068
4080
  $unsubscribe: function $unsubscribe (ref) {
4069
4081
  var vid = ref.vid;
4070
-
4071
- delete this.refs[vid];
4072
- this.refs = Object.assign({}, this.refs);
4073
- },
4074
- validate: function validate () {
4075
- return Promise.all(values(this.refs).map(function (ref) {
4076
- return ref.validate().then(function (result) {
4077
- ref.applyResult(result);
4078
-
4079
- return result;
4080
- });
4081
- })).then(function (results) { return results.every(function (r) { return r.valid; }); });
4082
- },
4083
- reset: function reset () {
4084
- return values(this.refs).forEach(function (ref) {
4085
- ref.reset();
4086
- });
4087
- }
4088
- },
4089
- computed: {
4090
- ctx: function ctx () {
4091
- return values(this.refs).reduce(function (acc, provider) {
4092
- Object.keys(flagMergingStrategy).forEach(function (flag) {
4093
- if (!(flag in acc)) {
4094
- acc[flag] = provider.flags[flag];
4095
- return;
4096
- }
4097
-
4098
- acc[flag] = mergeFlags(acc[flag], provider.flags[flag], flag);
4099
- });
4100
-
4101
- acc.errors[provider.vid] = provider.messages;
4102
-
4103
- return acc;
4104
- }, { errors: {} });
4105
- }
4106
- },
4107
- render: function render (h) {
4108
- var this$1 = this;
4109
-
4110
- var slots = this.$scopedSlots.default;
4111
- if (!isCallable(slots)) {
4112
- slots = function () { return normalizeSlots(this$1.$slots, this$1.$vnode.context); };
4113
- }
4114
-
4115
- var nodes = slots(this.ctx);
4116
-
4117
- return h(this.tag, {
4118
- attrs: this.$attrs,
4119
- on: this.$listeners
4120
- }, Array.isArray(nodes) ? nodes : [nodes]);
4121
- }
4082
+
4083
+ delete this.refs[vid];
4084
+ this.refs = Object.assign({}, this.refs);
4085
+ },
4086
+ validate: function validate () {
4087
+ return Promise.all(values(this.refs).map(function (ref) {
4088
+ return ref.validate().then(function (result) {
4089
+ ref.applyResult(result);
4090
+
4091
+ return result;
4092
+ });
4093
+ })).then(function (results) { return results.every(function (r) { return r.valid; }); });
4094
+ },
4095
+ reset: function reset () {
4096
+ return values(this.refs).forEach(function (ref) {
4097
+ ref.reset();
4098
+ });
4099
+ }
4100
+ },
4101
+ computed: {
4102
+ ctx: function ctx () {
4103
+ return values(this.refs).reduce(function (acc, provider) {
4104
+ Object.keys(flagMergingStrategy).forEach(function (flag) {
4105
+ if (!(flag in acc)) {
4106
+ acc[flag] = provider.flags[flag];
4107
+ return;
4108
+ }
4109
+
4110
+ acc[flag] = mergeFlags(acc[flag], provider.flags[flag], flag);
4111
+ });
4112
+
4113
+ acc.errors[provider.vid] = provider.messages;
4114
+
4115
+ return acc;
4116
+ }, { errors: {} });
4117
+ }
4118
+ },
4119
+ render: function render (h) {
4120
+ var slots = this.$scopedSlots.default;
4121
+ if (!isCallable(slots)) {
4122
+ if (process.env.NODE_ENV !== 'production') {
4123
+ warn('ValidationObserver expects a scoped slot. Did you forget to add "slot-scope" to your slot?');
4124
+ }
4125
+
4126
+ return createRenderless(h, this.$slots.default);
4127
+ }
4128
+
4129
+ return createRenderless(h, slots(this.ctx));
4130
+ }
4122
4131
  };
4123
4132
 
4124
4133
  function withValidation (component, ctxToProps) {
@@ -4475,7 +4484,7 @@ VeeValidate.prototype.resolveConfig = function resolveConfig (ctx) {
4475
4484
  Object.defineProperties( VeeValidate.prototype, prototypeAccessors$6 );
4476
4485
  Object.defineProperties( VeeValidate, staticAccessors$2 );
4477
4486
 
4478
- VeeValidate.version = '2.1.2';
4487
+ VeeValidate.version = '2.1.3';
4479
4488
  VeeValidate.mixin = mixin;
4480
4489
  VeeValidate.directive = directive;
4481
4490
  VeeValidate.Validator = Validator;
@@ -4485,7 +4494,7 @@ VeeValidate.ValidationProvider = ValidationProvider;
4485
4494
  VeeValidate.ValidationObserver = ValidationObserver;
4486
4495
  VeeValidate.withValidation = withValidation;
4487
4496
 
4488
- var version = '2.1.2';
4497
+ var version = '2.1.3';
4489
4498
  var install = VeeValidate.install;
4490
4499
  var use = VeeValidate.use;
4491
4500