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
  */
@@ -5238,130 +5238,148 @@
5238
5238
  }, {});
5239
5239
  };
5240
5240
 
5241
- // VNode Utils
5242
-
5243
- // Gets the model object on the vnode.
5244
- function findModel (vnode) {
5245
- if (!vnode.data) {
5246
- return null;
5247
- }
5248
-
5249
- // Component Model
5250
- if (vnode.data.model) {
5251
- return vnode.data.model;
5252
- }
5253
-
5254
- return !!(vnode.data.directives) && find(vnode.data.directives, function (d) { return d.name === 'model'; });
5255
- }
5256
-
5257
- function extractVNodes (vnode) {
5258
- if (findModel(vnode)) {
5259
- return [vnode];
5260
- }
5261
-
5262
- var children = Array.isArray(vnode) ? vnode : vnode.children;
5263
- if (!Array.isArray(children)) {
5264
- return [];
5265
- }
5266
-
5267
- return children.reduce(function (nodes, node) {
5268
- var candidates = extractVNodes(node);
5269
- if (candidates.length) {
5270
- nodes.push.apply(nodes, candidates);
5271
- }
5272
-
5273
- return nodes;
5274
- }, []);
5275
- }
5276
-
5277
- // Resolves v-model config if exists.
5278
- function findModelConfig (vnode) {
5279
- if (!vnode.componentOptions) { return null; }
5280
-
5281
- return vnode.componentOptions.Ctor.options.model;
5282
- }
5283
- // Adds a listener to vnode listener object.
5284
- function mergeVNodeListeners (obj, eventName, handler) {
5285
- // Has a single listener.
5286
- if (isCallable(obj[eventName])) {
5287
- var prevHandler = obj[eventName];
5288
- obj[eventName] = [prevHandler];
5289
- }
5290
-
5291
- // has other listeners.
5292
- if (Array.isArray(obj[eventName])) {
5293
- obj[eventName].push(handler);
5294
- return;
5295
- }
5296
-
5297
- // no listener at all.
5298
- if (isNullOrUndefined(obj[eventName])) {
5299
- obj[eventName] = [handler];
5300
- }
5301
- }
5302
-
5303
- // Adds a listener to a native HTML vnode.
5304
- function addNativeNodeListener (node, eventName, handler) {
5305
- if (isNullOrUndefined(node.data.on)) {
5306
- node.data.on = {};
5307
- }
5308
-
5309
- mergeVNodeListeners(node.data.on, eventName, handler);
5310
- }
5311
-
5312
- // Adds a listener to a Vue component vnode.
5313
- function addComponentNodeListener (node, eventName, handler) {
5314
- /* istanbul ignore next */
5315
- if (!node.componentOptions.listeners) {
5316
- node.componentOptions.listeners = {};
5317
- }
5318
-
5319
- mergeVNodeListeners(node.componentOptions.listeners, eventName, handler);
5320
- }
5321
- function addVNodeListener (vnode, eventName, handler) {
5322
- if (vnode.componentOptions) {
5323
- addComponentNodeListener(vnode, eventName, handler);
5324
- }
5325
-
5326
- addNativeNodeListener(vnode, eventName, handler);
5327
- }
5328
- // Determines if `change` should be used over `input` for listeners.
5329
- function getInputEventName (vnode, model) {
5330
- // Is a component.
5331
- if (vnode.componentOptions) {
5241
+ // VNode Utils
5242
+
5243
+ // Gets the model object on the vnode.
5244
+ function findModel (vnode) {
5245
+ if (!vnode.data) {
5246
+ return null;
5247
+ }
5248
+
5249
+ // Component Model
5250
+ if (vnode.data.model) {
5251
+ return vnode.data.model;
5252
+ }
5253
+
5254
+ return !!(vnode.data.directives) && find(vnode.data.directives, function (d) { return d.name === 'model'; });
5255
+ }
5256
+
5257
+ function extractVNodes (vnode) {
5258
+ if (findModel(vnode)) {
5259
+ return [vnode];
5260
+ }
5261
+
5262
+ var children = Array.isArray(vnode) ? vnode : vnode.children;
5263
+ if (!Array.isArray(children)) {
5264
+ return [];
5265
+ }
5266
+
5267
+ return children.reduce(function (nodes, node) {
5268
+ var candidates = extractVNodes(node);
5269
+ if (candidates.length) {
5270
+ nodes.push.apply(nodes, candidates);
5271
+ }
5272
+
5273
+ return nodes;
5274
+ }, []);
5275
+ }
5276
+
5277
+ // Resolves v-model config if exists.
5278
+ function findModelConfig (vnode) {
5279
+ if (!vnode.componentOptions) { return null; }
5280
+
5281
+ return vnode.componentOptions.Ctor.options.model;
5282
+ }
5283
+ // Adds a listener to vnode listener object.
5284
+ function mergeVNodeListeners (obj, eventName, handler) {
5285
+ // Has a single listener.
5286
+ if (isCallable(obj[eventName])) {
5287
+ var prevHandler = obj[eventName];
5288
+ obj[eventName] = [prevHandler];
5289
+ }
5290
+
5291
+ // has other listeners.
5292
+ if (Array.isArray(obj[eventName])) {
5293
+ obj[eventName].push(handler);
5294
+ return;
5295
+ }
5296
+
5297
+ // no listener at all.
5298
+ if (isNullOrUndefined(obj[eventName])) {
5299
+ obj[eventName] = [handler];
5300
+ }
5301
+ }
5302
+
5303
+ // Adds a listener to a native HTML vnode.
5304
+ function addNativeNodeListener (node, eventName, handler) {
5305
+ if (isNullOrUndefined(node.data.on)) {
5306
+ node.data.on = {};
5307
+ }
5308
+
5309
+ mergeVNodeListeners(node.data.on, eventName, handler);
5310
+ }
5311
+
5312
+ // Adds a listener to a Vue component vnode.
5313
+ function addComponentNodeListener (node, eventName, handler) {
5314
+ /* istanbul ignore next */
5315
+ if (!node.componentOptions.listeners) {
5316
+ node.componentOptions.listeners = {};
5317
+ }
5318
+
5319
+ mergeVNodeListeners(node.componentOptions.listeners, eventName, handler);
5320
+ }
5321
+ function addVNodeListener (vnode, eventName, handler) {
5322
+ if (vnode.componentOptions) {
5323
+ addComponentNodeListener(vnode, eventName, handler);
5324
+ }
5325
+
5326
+ addNativeNodeListener(vnode, eventName, handler);
5327
+ }
5328
+ // Determines if `change` should be used over `input` for listeners.
5329
+ function getInputEventName (vnode, model) {
5330
+ // Is a component.
5331
+ if (vnode.componentOptions) {
5332
5332
  var ref = findModelConfig(vnode) || { event: 'input' };
5333
- var event = ref.event;
5334
-
5335
- return event;
5336
- }
5337
-
5338
- // Lazy Models typically use change event
5339
- if (model && model.modifiers && model.modifiers.lazy) {
5340
- return 'change';
5341
- }
5342
-
5343
- // is a textual-type input.
5344
- if (vnode.data.attrs && isTextInput({ type: vnode.data.attrs.type || 'text' })) {
5345
- return 'input';
5346
- }
5347
-
5348
- return 'change';
5349
- }
5350
-
5351
- function normalizeSlots (slots, ctx) {
5352
- return Object.keys(slots).reduce(function (arr, key) {
5353
- slots[key].forEach(function (vnode) {
5354
- if (!vnode.context) {
5355
- slots[key].context = ctx;
5356
- if (!vnode.data) {
5357
- vnode.data = {};
5358
- }
5359
- vnode.data.slot = key;
5360
- }
5361
- });
5362
-
5363
- return arr.concat(slots[key]);
5364
- }, []);
5333
+ var event = ref.event;
5334
+
5335
+ return event;
5336
+ }
5337
+
5338
+ // Lazy Models typically use change event
5339
+ if (model && model.modifiers && model.modifiers.lazy) {
5340
+ return 'change';
5341
+ }
5342
+
5343
+ // is a textual-type input.
5344
+ if (vnode.data.attrs && isTextInput({ type: vnode.data.attrs.type || 'text' })) {
5345
+ return 'input';
5346
+ }
5347
+
5348
+ return 'change';
5349
+ }
5350
+
5351
+ function normalizeSlots (slots, ctx) {
5352
+ return Object.keys(slots).reduce(function (arr, key) {
5353
+ slots[key].forEach(function (vnode) {
5354
+ if (!vnode.context) {
5355
+ slots[key].context = ctx;
5356
+ if (!vnode.data) {
5357
+ vnode.data = {};
5358
+ }
5359
+ vnode.data.slot = key;
5360
+ }
5361
+ });
5362
+
5363
+ return arr.concat(slots[key]);
5364
+ }, []);
5365
+ }
5366
+
5367
+ function createRenderless (h, vnode) {
5368
+ // a single-root slot yay!
5369
+ if (!Array.isArray(vnode)) {
5370
+ return vnode;
5371
+ }
5372
+
5373
+ if (vnode.length === 1) {
5374
+ return vnode[0];
5375
+ }
5376
+
5377
+ {
5378
+ warn('Your slot should have one root element. Rendering a span as the root.');
5379
+ }
5380
+
5381
+ // Renders a multi-root node, should throw a Vue error.
5382
+ return vnode;
5365
5383
  }
5366
5384
 
5367
5385
  /**
@@ -5709,7 +5727,7 @@
5709
5727
  //
5710
5728
 
5711
5729
  var isEvent = function (evt) {
5712
- return (isCallable(Event) && evt instanceof Event) || (evt && evt.srcElement);
5730
+ return (typeof Event !== 'undefined' && isCallable(Event) && evt instanceof Event) || (evt && evt.srcElement);
5713
5731
  };
5714
5732
 
5715
5733
  var normalizeEvents = function (evts) {
@@ -6975,7 +6993,9 @@
6975
6993
  /**
6976
6994
  * Registers a field to be validated.
6977
6995
  */
6978
- Validator.prototype.attach = function attach (fieldOpts) {
6996
+ Validator.prototype.attach = function attach (fieldOpts) {
6997
+ var this$1 = this;
6998
+
6979
6999
  // fixes initial value detection with v-model and select elements.
6980
7000
  var value = fieldOpts.initialValue;
6981
7001
  var field = new Field(fieldOpts);
@@ -6983,7 +7003,7 @@
6983
7003
 
6984
7004
  // validate the field initially
6985
7005
  if (field.immediate) {
6986
- this.validate(("#" + (field.id)), value || field.value, { vmId: fieldOpts.vmId });
7006
+ VeeValidate$1.instance._vm.$nextTick(function () { return this$1.validate(("#" + (field.id)), value || field.value, { vmId: fieldOpts.vmId }); });
6987
7007
  } else {
6988
7008
  this._validate(field, value || field.value, { initial: true }).then(function (result) {
6989
7009
  field.flags.valid = result.valid;
@@ -7764,7 +7784,7 @@
7764
7784
  });
7765
7785
  };
7766
7786
 
7767
- this.syncValue(model.value);
7787
+ this.value = model.value;
7768
7788
  this.validate().then(this.immediate || shouldRevalidate ? this.applyResult : silentHandler);
7769
7789
  }
7770
7790
 
@@ -7828,11 +7848,16 @@
7828
7848
  var providers = ctx.$_veeObserver.refs;
7829
7849
 
7830
7850
  return ctx.fieldDeps.reduce(function (acc, depName) {
7831
- if (providers[depName]) {
7832
- acc[depName] = providers[depName].value;
7833
- var unwatch = providers[depName].$watch('value', function () {
7851
+ if (!providers[depName]) {
7852
+ return acc;
7853
+ }
7854
+
7855
+ acc[depName] = providers[depName].value;
7856
+ var watcherName = "$__" + depName;
7857
+ if (!isCallable(ctx[watcherName])) {
7858
+ ctx[watcherName] = providers[depName].$watch('value', function () {
7834
7859
  ctx.validate(ctx.value).then(ctx.applyResult);
7835
- unwatch();
7860
+ ctx[watcherName]();
7836
7861
  });
7837
7862
  }
7838
7863
 
@@ -7910,10 +7935,6 @@
7910
7935
  type: Boolean,
7911
7936
  default: false
7912
7937
  },
7913
- tag: {
7914
- type: String,
7915
- default: 'span'
7916
- },
7917
7938
  bails: {
7918
7939
  type: Boolean,
7919
7940
  default: function () { return VeeValidate$1.config.fastExit; }
@@ -8052,22 +8073,19 @@
8052
8073
  var slot = this.$scopedSlots.default;
8053
8074
  if (!isCallable(slot)) {
8054
8075
  {
8055
- warn('Did you forget to add a scoped slot to the ValidationProvider?');
8076
+ warn('ValidationProvider expects a scoped slot. Did you forget to add "slot-scope" to your slot?');
8056
8077
  }
8057
8078
 
8058
- slot = function () { return normalizeSlots(this$1.$slots, this$1.$vnode.context); };
8079
+ return createRenderless(h, this.$slots.default);
8059
8080
  }
8060
8081
 
8061
8082
  var nodes = slot(ctx);
8062
8083
  // Handle single-root slot.
8063
- nodes = Array.isArray(nodes) ? nodes : [nodes];
8064
- extractVNodes({ children: nodes }).forEach(function (input) {
8084
+ extractVNodes(nodes).forEach(function (input) {
8065
8085
  addListeners.call(this$1, input);
8066
8086
  });
8067
8087
 
8068
- return h(this.tag, {
8069
- attrs: this.$attrs
8070
- }, nodes);
8088
+ return createRenderless(h, nodes);
8071
8089
  },
8072
8090
  beforeDestroy: function beforeDestroy () {
8073
8091
  // cleanup reference.
@@ -8075,99 +8093,90 @@
8075
8093
  }
8076
8094
  };
8077
8095
 
8078
- var flagMergingStrategy = {
8079
- pristine: 'every',
8080
- dirty: 'some',
8081
- touched: 'some',
8082
- untouched: 'every',
8083
- valid: 'every',
8084
- invalid: 'some',
8085
- pending: 'some',
8086
- validated: 'every'
8087
- };
8088
-
8089
- function mergeFlags (lhs, rhs, strategy) {
8090
- var stratName = flagMergingStrategy[strategy];
8091
-
8092
- return [lhs, rhs][stratName](function (f) { return f; });
8093
- }
8094
-
8095
- var ValidationObserver = {
8096
- name: 'ValidationObserver',
8097
- provide: function provide () {
8098
- return {
8099
- $_veeObserver: this
8100
- };
8101
- },
8102
- props: {
8103
- tag: {
8104
- type: String,
8105
- default: 'span'
8106
- }
8107
- },
8108
- data: function () { return ({
8109
- refs: {}
8110
- }); },
8111
- methods: {
8096
+ var flagMergingStrategy = {
8097
+ pristine: 'every',
8098
+ dirty: 'some',
8099
+ touched: 'some',
8100
+ untouched: 'every',
8101
+ valid: 'every',
8102
+ invalid: 'some',
8103
+ pending: 'some',
8104
+ validated: 'every'
8105
+ };
8106
+
8107
+ function mergeFlags (lhs, rhs, strategy) {
8108
+ var stratName = flagMergingStrategy[strategy];
8109
+
8110
+ return [lhs, rhs][stratName](function (f) { return f; });
8111
+ }
8112
+
8113
+ var ValidationObserver = {
8114
+ name: 'ValidationObserver',
8115
+ provide: function provide () {
8116
+ return {
8117
+ $_veeObserver: this
8118
+ };
8119
+ },
8120
+ data: function () { return ({
8121
+ refs: {}
8122
+ }); },
8123
+ methods: {
8112
8124
  $subscribe: function $subscribe (provider) {
8113
8125
  var obj;
8114
-
8115
- this.refs = Object.assign({}, this.refs, ( obj = {}, obj[provider.vid] = provider, obj ));
8116
- },
8126
+
8127
+ this.refs = Object.assign({}, this.refs, ( obj = {}, obj[provider.vid] = provider, obj ));
8128
+ },
8117
8129
  $unsubscribe: function $unsubscribe (ref) {
8118
8130
  var vid = ref.vid;
8119
-
8120
- delete this.refs[vid];
8121
- this.refs = Object.assign({}, this.refs);
8122
- },
8123
- validate: function validate () {
8124
- return Promise.all(values(this.refs).map(function (ref) {
8125
- return ref.validate().then(function (result) {
8126
- ref.applyResult(result);
8127
-
8128
- return result;
8129
- });
8130
- })).then(function (results) { return results.every(function (r) { return r.valid; }); });
8131
- },
8132
- reset: function reset () {
8133
- return values(this.refs).forEach(function (ref) {
8134
- ref.reset();
8135
- });
8136
- }
8137
- },
8138
- computed: {
8139
- ctx: function ctx () {
8140
- return values(this.refs).reduce(function (acc, provider) {
8141
- Object.keys(flagMergingStrategy).forEach(function (flag) {
8142
- if (!(flag in acc)) {
8143
- acc[flag] = provider.flags[flag];
8144
- return;
8145
- }
8146
-
8147
- acc[flag] = mergeFlags(acc[flag], provider.flags[flag], flag);
8148
- });
8149
-
8150
- acc.errors[provider.vid] = provider.messages;
8151
-
8152
- return acc;
8153
- }, { errors: {} });
8154
- }
8155
- },
8156
- render: function render (h) {
8157
- var this$1 = this;
8158
-
8159
- var slots = this.$scopedSlots.default;
8160
- if (!isCallable(slots)) {
8161
- slots = function () { return normalizeSlots(this$1.$slots, this$1.$vnode.context); };
8162
- }
8163
-
8164
- var nodes = slots(this.ctx);
8165
-
8166
- return h(this.tag, {
8167
- attrs: this.$attrs,
8168
- on: this.$listeners
8169
- }, Array.isArray(nodes) ? nodes : [nodes]);
8170
- }
8131
+
8132
+ delete this.refs[vid];
8133
+ this.refs = Object.assign({}, this.refs);
8134
+ },
8135
+ validate: function validate () {
8136
+ return Promise.all(values(this.refs).map(function (ref) {
8137
+ return ref.validate().then(function (result) {
8138
+ ref.applyResult(result);
8139
+
8140
+ return result;
8141
+ });
8142
+ })).then(function (results) { return results.every(function (r) { return r.valid; }); });
8143
+ },
8144
+ reset: function reset () {
8145
+ return values(this.refs).forEach(function (ref) {
8146
+ ref.reset();
8147
+ });
8148
+ }
8149
+ },
8150
+ computed: {
8151
+ ctx: function ctx () {
8152
+ return values(this.refs).reduce(function (acc, provider) {
8153
+ Object.keys(flagMergingStrategy).forEach(function (flag) {
8154
+ if (!(flag in acc)) {
8155
+ acc[flag] = provider.flags[flag];
8156
+ return;
8157
+ }
8158
+
8159
+ acc[flag] = mergeFlags(acc[flag], provider.flags[flag], flag);
8160
+ });
8161
+
8162
+ acc.errors[provider.vid] = provider.messages;
8163
+
8164
+ return acc;
8165
+ }, { errors: {} });
8166
+ }
8167
+ },
8168
+ render: function render (h) {
8169
+ var slots = this.$scopedSlots.default;
8170
+ if (!isCallable(slots)) {
8171
+ {
8172
+ warn('ValidationObserver expects a scoped slot. Did you forget to add "slot-scope" to your slot?');
8173
+ }
8174
+
8175
+ return createRenderless(h, this.$slots.default);
8176
+ }
8177
+
8178
+ return createRenderless(h, slots(this.ctx));
8179
+ }
8171
8180
  };
8172
8181
 
8173
8182
  function withValidation (component, ctxToProps) {
@@ -8524,7 +8533,7 @@
8524
8533
  Object.defineProperties( VeeValidate$1.prototype, prototypeAccessors$6 );
8525
8534
  Object.defineProperties( VeeValidate$1, staticAccessors$2 );
8526
8535
 
8527
- VeeValidate$1.version = '2.1.2';
8536
+ VeeValidate$1.version = '2.1.3';
8528
8537
  VeeValidate$1.mixin = mixin;
8529
8538
  VeeValidate$1.directive = directive;
8530
8539
  VeeValidate$1.Validator = Validator;