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
  */
@@ -1195,130 +1195,148 @@
1195
1195
  }, {});
1196
1196
  };
1197
1197
 
1198
- // VNode Utils
1199
-
1200
- // Gets the model object on the vnode.
1201
- function findModel (vnode) {
1202
- if (!vnode.data) {
1203
- return null;
1204
- }
1205
-
1206
- // Component Model
1207
- if (vnode.data.model) {
1208
- return vnode.data.model;
1209
- }
1210
-
1211
- return !!(vnode.data.directives) && find(vnode.data.directives, function (d) { return d.name === 'model'; });
1212
- }
1213
-
1214
- function extractVNodes (vnode) {
1215
- if (findModel(vnode)) {
1216
- return [vnode];
1217
- }
1218
-
1219
- var children = Array.isArray(vnode) ? vnode : vnode.children;
1220
- if (!Array.isArray(children)) {
1221
- return [];
1222
- }
1223
-
1224
- return children.reduce(function (nodes, node) {
1225
- var candidates = extractVNodes(node);
1226
- if (candidates.length) {
1227
- nodes.push.apply(nodes, candidates);
1228
- }
1229
-
1230
- return nodes;
1231
- }, []);
1232
- }
1233
-
1234
- // Resolves v-model config if exists.
1235
- function findModelConfig (vnode) {
1236
- if (!vnode.componentOptions) { return null; }
1237
-
1238
- return vnode.componentOptions.Ctor.options.model;
1239
- }
1240
- // Adds a listener to vnode listener object.
1241
- function mergeVNodeListeners (obj, eventName, handler) {
1242
- // Has a single listener.
1243
- if (isCallable(obj[eventName])) {
1244
- var prevHandler = obj[eventName];
1245
- obj[eventName] = [prevHandler];
1246
- }
1247
-
1248
- // has other listeners.
1249
- if (Array.isArray(obj[eventName])) {
1250
- obj[eventName].push(handler);
1251
- return;
1252
- }
1253
-
1254
- // no listener at all.
1255
- if (isNullOrUndefined(obj[eventName])) {
1256
- obj[eventName] = [handler];
1257
- }
1258
- }
1259
-
1260
- // Adds a listener to a native HTML vnode.
1261
- function addNativeNodeListener (node, eventName, handler) {
1262
- if (isNullOrUndefined(node.data.on)) {
1263
- node.data.on = {};
1264
- }
1265
-
1266
- mergeVNodeListeners(node.data.on, eventName, handler);
1267
- }
1268
-
1269
- // Adds a listener to a Vue component vnode.
1270
- function addComponentNodeListener (node, eventName, handler) {
1271
- /* istanbul ignore next */
1272
- if (!node.componentOptions.listeners) {
1273
- node.componentOptions.listeners = {};
1274
- }
1275
-
1276
- mergeVNodeListeners(node.componentOptions.listeners, eventName, handler);
1277
- }
1278
- function addVNodeListener (vnode, eventName, handler) {
1279
- if (vnode.componentOptions) {
1280
- addComponentNodeListener(vnode, eventName, handler);
1281
- }
1282
-
1283
- addNativeNodeListener(vnode, eventName, handler);
1284
- }
1285
- // Determines if `change` should be used over `input` for listeners.
1286
- function getInputEventName (vnode, model) {
1287
- // Is a component.
1288
- if (vnode.componentOptions) {
1198
+ // VNode Utils
1199
+
1200
+ // Gets the model object on the vnode.
1201
+ function findModel (vnode) {
1202
+ if (!vnode.data) {
1203
+ return null;
1204
+ }
1205
+
1206
+ // Component Model
1207
+ if (vnode.data.model) {
1208
+ return vnode.data.model;
1209
+ }
1210
+
1211
+ return !!(vnode.data.directives) && find(vnode.data.directives, function (d) { return d.name === 'model'; });
1212
+ }
1213
+
1214
+ function extractVNodes (vnode) {
1215
+ if (findModel(vnode)) {
1216
+ return [vnode];
1217
+ }
1218
+
1219
+ var children = Array.isArray(vnode) ? vnode : vnode.children;
1220
+ if (!Array.isArray(children)) {
1221
+ return [];
1222
+ }
1223
+
1224
+ return children.reduce(function (nodes, node) {
1225
+ var candidates = extractVNodes(node);
1226
+ if (candidates.length) {
1227
+ nodes.push.apply(nodes, candidates);
1228
+ }
1229
+
1230
+ return nodes;
1231
+ }, []);
1232
+ }
1233
+
1234
+ // Resolves v-model config if exists.
1235
+ function findModelConfig (vnode) {
1236
+ if (!vnode.componentOptions) { return null; }
1237
+
1238
+ return vnode.componentOptions.Ctor.options.model;
1239
+ }
1240
+ // Adds a listener to vnode listener object.
1241
+ function mergeVNodeListeners (obj, eventName, handler) {
1242
+ // Has a single listener.
1243
+ if (isCallable(obj[eventName])) {
1244
+ var prevHandler = obj[eventName];
1245
+ obj[eventName] = [prevHandler];
1246
+ }
1247
+
1248
+ // has other listeners.
1249
+ if (Array.isArray(obj[eventName])) {
1250
+ obj[eventName].push(handler);
1251
+ return;
1252
+ }
1253
+
1254
+ // no listener at all.
1255
+ if (isNullOrUndefined(obj[eventName])) {
1256
+ obj[eventName] = [handler];
1257
+ }
1258
+ }
1259
+
1260
+ // Adds a listener to a native HTML vnode.
1261
+ function addNativeNodeListener (node, eventName, handler) {
1262
+ if (isNullOrUndefined(node.data.on)) {
1263
+ node.data.on = {};
1264
+ }
1265
+
1266
+ mergeVNodeListeners(node.data.on, eventName, handler);
1267
+ }
1268
+
1269
+ // Adds a listener to a Vue component vnode.
1270
+ function addComponentNodeListener (node, eventName, handler) {
1271
+ /* istanbul ignore next */
1272
+ if (!node.componentOptions.listeners) {
1273
+ node.componentOptions.listeners = {};
1274
+ }
1275
+
1276
+ mergeVNodeListeners(node.componentOptions.listeners, eventName, handler);
1277
+ }
1278
+ function addVNodeListener (vnode, eventName, handler) {
1279
+ if (vnode.componentOptions) {
1280
+ addComponentNodeListener(vnode, eventName, handler);
1281
+ }
1282
+
1283
+ addNativeNodeListener(vnode, eventName, handler);
1284
+ }
1285
+ // Determines if `change` should be used over `input` for listeners.
1286
+ function getInputEventName (vnode, model) {
1287
+ // Is a component.
1288
+ if (vnode.componentOptions) {
1289
1289
  var ref = findModelConfig(vnode) || { event: 'input' };
1290
- var event = ref.event;
1291
-
1292
- return event;
1293
- }
1294
-
1295
- // Lazy Models typically use change event
1296
- if (model && model.modifiers && model.modifiers.lazy) {
1297
- return 'change';
1298
- }
1299
-
1300
- // is a textual-type input.
1301
- if (vnode.data.attrs && isTextInput({ type: vnode.data.attrs.type || 'text' })) {
1302
- return 'input';
1303
- }
1304
-
1305
- return 'change';
1306
- }
1307
-
1308
- function normalizeSlots (slots, ctx) {
1309
- return Object.keys(slots).reduce(function (arr, key) {
1310
- slots[key].forEach(function (vnode) {
1311
- if (!vnode.context) {
1312
- slots[key].context = ctx;
1313
- if (!vnode.data) {
1314
- vnode.data = {};
1315
- }
1316
- vnode.data.slot = key;
1317
- }
1318
- });
1319
-
1320
- return arr.concat(slots[key]);
1321
- }, []);
1290
+ var event = ref.event;
1291
+
1292
+ return event;
1293
+ }
1294
+
1295
+ // Lazy Models typically use change event
1296
+ if (model && model.modifiers && model.modifiers.lazy) {
1297
+ return 'change';
1298
+ }
1299
+
1300
+ // is a textual-type input.
1301
+ if (vnode.data.attrs && isTextInput({ type: vnode.data.attrs.type || 'text' })) {
1302
+ return 'input';
1303
+ }
1304
+
1305
+ return 'change';
1306
+ }
1307
+
1308
+ function normalizeSlots (slots, ctx) {
1309
+ return Object.keys(slots).reduce(function (arr, key) {
1310
+ slots[key].forEach(function (vnode) {
1311
+ if (!vnode.context) {
1312
+ slots[key].context = ctx;
1313
+ if (!vnode.data) {
1314
+ vnode.data = {};
1315
+ }
1316
+ vnode.data.slot = key;
1317
+ }
1318
+ });
1319
+
1320
+ return arr.concat(slots[key]);
1321
+ }, []);
1322
+ }
1323
+
1324
+ function createRenderless (h, vnode) {
1325
+ // a single-root slot yay!
1326
+ if (!Array.isArray(vnode)) {
1327
+ return vnode;
1328
+ }
1329
+
1330
+ if (vnode.length === 1) {
1331
+ return vnode[0];
1332
+ }
1333
+
1334
+ {
1335
+ warn('Your slot should have one root element. Rendering a span as the root.');
1336
+ }
1337
+
1338
+ // Renders a multi-root node, should throw a Vue error.
1339
+ return vnode;
1322
1340
  }
1323
1341
 
1324
1342
  /**
@@ -1666,7 +1684,7 @@
1666
1684
  //
1667
1685
 
1668
1686
  var isEvent = function (evt) {
1669
- return (isCallable(Event) && evt instanceof Event) || (evt && evt.srcElement);
1687
+ return (typeof Event !== 'undefined' && isCallable(Event) && evt instanceof Event) || (evt && evt.srcElement);
1670
1688
  };
1671
1689
 
1672
1690
  var normalizeEvents = function (evts) {
@@ -2932,7 +2950,9 @@
2932
2950
  /**
2933
2951
  * Registers a field to be validated.
2934
2952
  */
2935
- Validator.prototype.attach = function attach (fieldOpts) {
2953
+ Validator.prototype.attach = function attach (fieldOpts) {
2954
+ var this$1 = this;
2955
+
2936
2956
  // fixes initial value detection with v-model and select elements.
2937
2957
  var value = fieldOpts.initialValue;
2938
2958
  var field = new Field(fieldOpts);
@@ -2940,7 +2960,7 @@
2940
2960
 
2941
2961
  // validate the field initially
2942
2962
  if (field.immediate) {
2943
- this.validate(("#" + (field.id)), value || field.value, { vmId: fieldOpts.vmId });
2963
+ VeeValidate.instance._vm.$nextTick(function () { return this$1.validate(("#" + (field.id)), value || field.value, { vmId: fieldOpts.vmId }); });
2944
2964
  } else {
2945
2965
  this._validate(field, value || field.value, { initial: true }).then(function (result) {
2946
2966
  field.flags.valid = result.valid;
@@ -3721,7 +3741,7 @@
3721
3741
  });
3722
3742
  };
3723
3743
 
3724
- this.syncValue(model.value);
3744
+ this.value = model.value;
3725
3745
  this.validate().then(this.immediate || shouldRevalidate ? this.applyResult : silentHandler);
3726
3746
  }
3727
3747
 
@@ -3785,11 +3805,16 @@
3785
3805
  var providers = ctx.$_veeObserver.refs;
3786
3806
 
3787
3807
  return ctx.fieldDeps.reduce(function (acc, depName) {
3788
- if (providers[depName]) {
3789
- acc[depName] = providers[depName].value;
3790
- var unwatch = providers[depName].$watch('value', function () {
3808
+ if (!providers[depName]) {
3809
+ return acc;
3810
+ }
3811
+
3812
+ acc[depName] = providers[depName].value;
3813
+ var watcherName = "$__" + depName;
3814
+ if (!isCallable(ctx[watcherName])) {
3815
+ ctx[watcherName] = providers[depName].$watch('value', function () {
3791
3816
  ctx.validate(ctx.value).then(ctx.applyResult);
3792
- unwatch();
3817
+ ctx[watcherName]();
3793
3818
  });
3794
3819
  }
3795
3820
 
@@ -3867,10 +3892,6 @@
3867
3892
  type: Boolean,
3868
3893
  default: false
3869
3894
  },
3870
- tag: {
3871
- type: String,
3872
- default: 'span'
3873
- },
3874
3895
  bails: {
3875
3896
  type: Boolean,
3876
3897
  default: function () { return VeeValidate.config.fastExit; }
@@ -4009,22 +4030,19 @@
4009
4030
  var slot = this.$scopedSlots.default;
4010
4031
  if (!isCallable(slot)) {
4011
4032
  {
4012
- warn('Did you forget to add a scoped slot to the ValidationProvider?');
4033
+ warn('ValidationProvider expects a scoped slot. Did you forget to add "slot-scope" to your slot?');
4013
4034
  }
4014
4035
 
4015
- slot = function () { return normalizeSlots(this$1.$slots, this$1.$vnode.context); };
4036
+ return createRenderless(h, this.$slots.default);
4016
4037
  }
4017
4038
 
4018
4039
  var nodes = slot(ctx);
4019
4040
  // Handle single-root slot.
4020
- nodes = Array.isArray(nodes) ? nodes : [nodes];
4021
- extractVNodes({ children: nodes }).forEach(function (input) {
4041
+ extractVNodes(nodes).forEach(function (input) {
4022
4042
  addListeners.call(this$1, input);
4023
4043
  });
4024
4044
 
4025
- return h(this.tag, {
4026
- attrs: this.$attrs
4027
- }, nodes);
4045
+ return createRenderless(h, nodes);
4028
4046
  },
4029
4047
  beforeDestroy: function beforeDestroy () {
4030
4048
  // cleanup reference.
@@ -4032,99 +4050,90 @@
4032
4050
  }
4033
4051
  };
4034
4052
 
4035
- var flagMergingStrategy = {
4036
- pristine: 'every',
4037
- dirty: 'some',
4038
- touched: 'some',
4039
- untouched: 'every',
4040
- valid: 'every',
4041
- invalid: 'some',
4042
- pending: 'some',
4043
- validated: 'every'
4044
- };
4045
-
4046
- function mergeFlags (lhs, rhs, strategy) {
4047
- var stratName = flagMergingStrategy[strategy];
4048
-
4049
- return [lhs, rhs][stratName](function (f) { return f; });
4050
- }
4051
-
4052
- var ValidationObserver = {
4053
- name: 'ValidationObserver',
4054
- provide: function provide () {
4055
- return {
4056
- $_veeObserver: this
4057
- };
4058
- },
4059
- props: {
4060
- tag: {
4061
- type: String,
4062
- default: 'span'
4063
- }
4064
- },
4065
- data: function () { return ({
4066
- refs: {}
4067
- }); },
4068
- methods: {
4053
+ var flagMergingStrategy = {
4054
+ pristine: 'every',
4055
+ dirty: 'some',
4056
+ touched: 'some',
4057
+ untouched: 'every',
4058
+ valid: 'every',
4059
+ invalid: 'some',
4060
+ pending: 'some',
4061
+ validated: 'every'
4062
+ };
4063
+
4064
+ function mergeFlags (lhs, rhs, strategy) {
4065
+ var stratName = flagMergingStrategy[strategy];
4066
+
4067
+ return [lhs, rhs][stratName](function (f) { return f; });
4068
+ }
4069
+
4070
+ var ValidationObserver = {
4071
+ name: 'ValidationObserver',
4072
+ provide: function provide () {
4073
+ return {
4074
+ $_veeObserver: this
4075
+ };
4076
+ },
4077
+ data: function () { return ({
4078
+ refs: {}
4079
+ }); },
4080
+ methods: {
4069
4081
  $subscribe: function $subscribe (provider) {
4070
4082
  var obj;
4071
-
4072
- this.refs = Object.assign({}, this.refs, ( obj = {}, obj[provider.vid] = provider, obj ));
4073
- },
4083
+
4084
+ this.refs = Object.assign({}, this.refs, ( obj = {}, obj[provider.vid] = provider, obj ));
4085
+ },
4074
4086
  $unsubscribe: function $unsubscribe (ref) {
4075
4087
  var vid = ref.vid;
4076
-
4077
- delete this.refs[vid];
4078
- this.refs = Object.assign({}, this.refs);
4079
- },
4080
- validate: function validate () {
4081
- return Promise.all(values(this.refs).map(function (ref) {
4082
- return ref.validate().then(function (result) {
4083
- ref.applyResult(result);
4084
-
4085
- return result;
4086
- });
4087
- })).then(function (results) { return results.every(function (r) { return r.valid; }); });
4088
- },
4089
- reset: function reset () {
4090
- return values(this.refs).forEach(function (ref) {
4091
- ref.reset();
4092
- });
4093
- }
4094
- },
4095
- computed: {
4096
- ctx: function ctx () {
4097
- return values(this.refs).reduce(function (acc, provider) {
4098
- Object.keys(flagMergingStrategy).forEach(function (flag) {
4099
- if (!(flag in acc)) {
4100
- acc[flag] = provider.flags[flag];
4101
- return;
4102
- }
4103
-
4104
- acc[flag] = mergeFlags(acc[flag], provider.flags[flag], flag);
4105
- });
4106
-
4107
- acc.errors[provider.vid] = provider.messages;
4108
-
4109
- return acc;
4110
- }, { errors: {} });
4111
- }
4112
- },
4113
- render: function render (h) {
4114
- var this$1 = this;
4115
-
4116
- var slots = this.$scopedSlots.default;
4117
- if (!isCallable(slots)) {
4118
- slots = function () { return normalizeSlots(this$1.$slots, this$1.$vnode.context); };
4119
- }
4120
-
4121
- var nodes = slots(this.ctx);
4122
-
4123
- return h(this.tag, {
4124
- attrs: this.$attrs,
4125
- on: this.$listeners
4126
- }, Array.isArray(nodes) ? nodes : [nodes]);
4127
- }
4088
+
4089
+ delete this.refs[vid];
4090
+ this.refs = Object.assign({}, this.refs);
4091
+ },
4092
+ validate: function validate () {
4093
+ return Promise.all(values(this.refs).map(function (ref) {
4094
+ return ref.validate().then(function (result) {
4095
+ ref.applyResult(result);
4096
+
4097
+ return result;
4098
+ });
4099
+ })).then(function (results) { return results.every(function (r) { return r.valid; }); });
4100
+ },
4101
+ reset: function reset () {
4102
+ return values(this.refs).forEach(function (ref) {
4103
+ ref.reset();
4104
+ });
4105
+ }
4106
+ },
4107
+ computed: {
4108
+ ctx: function ctx () {
4109
+ return values(this.refs).reduce(function (acc, provider) {
4110
+ Object.keys(flagMergingStrategy).forEach(function (flag) {
4111
+ if (!(flag in acc)) {
4112
+ acc[flag] = provider.flags[flag];
4113
+ return;
4114
+ }
4115
+
4116
+ acc[flag] = mergeFlags(acc[flag], provider.flags[flag], flag);
4117
+ });
4118
+
4119
+ acc.errors[provider.vid] = provider.messages;
4120
+
4121
+ return acc;
4122
+ }, { errors: {} });
4123
+ }
4124
+ },
4125
+ render: function render (h) {
4126
+ var slots = this.$scopedSlots.default;
4127
+ if (!isCallable(slots)) {
4128
+ {
4129
+ warn('ValidationObserver expects a scoped slot. Did you forget to add "slot-scope" to your slot?');
4130
+ }
4131
+
4132
+ return createRenderless(h, this.$slots.default);
4133
+ }
4134
+
4135
+ return createRenderless(h, slots(this.ctx));
4136
+ }
4128
4137
  };
4129
4138
 
4130
4139
  function withValidation (component, ctxToProps) {
@@ -4481,7 +4490,7 @@
4481
4490
  Object.defineProperties( VeeValidate.prototype, prototypeAccessors$6 );
4482
4491
  Object.defineProperties( VeeValidate, staticAccessors$2 );
4483
4492
 
4484
- VeeValidate.version = '2.1.2';
4493
+ VeeValidate.version = '2.1.3';
4485
4494
  VeeValidate.mixin = mixin;
4486
4495
  VeeValidate.directive = directive;
4487
4496
  VeeValidate.Validator = Validator;