vee-validate 2.2.9 → 2.2.13

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.2.9
2
+ * vee-validate v2.2.13
3
3
  * (c) 2019 Abdelrahman Awad
4
4
  * @license MIT
5
5
  */
@@ -28,7 +28,7 @@ var isNaN = function (value) {
28
28
  }
29
29
 
30
30
  // eslint-disable-next-line
31
- return value === value;
31
+ return typeof(value) === 'number' && value !== value;
32
32
  };
33
33
 
34
34
  /**
@@ -771,6 +771,10 @@ Dictionary.prototype.setMessage = function setMessage (locale, key, message) {
771
771
  attributes: {}
772
772
  };
773
773
  }
774
+
775
+ if (!this.container[locale].messages) {
776
+ this.container[locale].messages = {};
777
+ }
774
778
 
775
779
  this.container[locale].messages[key] = message;
776
780
  };
@@ -958,12 +962,15 @@ ErrorBag.prototype.clear = function clear (scope) {
958
962
  var this$1 = this;
959
963
 
960
964
  var matchesVM = isNullOrUndefined(this.vmId) ? function () { return true; } : function (i) { return i.vmId === this$1.vmId; };
961
- if (isNullOrUndefined(scope)) {
965
+ var matchesScope = function (i) { return i.scope === scope; };
966
+ if (arguments.length === 0) {
967
+ matchesScope = function () { return true; };
968
+ } else if (isNullOrUndefined(scope)) {
962
969
  scope = null;
963
970
  }
964
971
 
965
972
  for (var i = 0; i < this.items.length; ++i) {
966
- if (matchesVM(this.items[i]) && this.items[i].scope === scope) {
973
+ if (matchesVM(this.items[i]) && matchesScope(this.items[i])) {
967
974
  this.items.splice(i, 1);
968
975
  --i;
969
976
  }
@@ -1407,6 +1414,20 @@ function normalizeSlots (slots, ctx) {
1407
1414
  return arr.concat(slots[key]);
1408
1415
  }, []);
1409
1416
  }
1417
+ function createRenderless (h, children) {
1418
+ // Only render the first item of the node.
1419
+ if (Array.isArray(children) && children[0]) {
1420
+ return children[0];
1421
+ }
1422
+
1423
+ // a single node.
1424
+ if (children) {
1425
+ return children;
1426
+ }
1427
+
1428
+ // No slots, render nothing.
1429
+ return h();
1430
+ }
1410
1431
 
1411
1432
  /**
1412
1433
  * Generates the options required to construct a field.
@@ -1832,7 +1853,7 @@ var prototypeAccessors$1 = { validator: { configurable: true },isRequired: { con
1832
1853
 
1833
1854
  prototypeAccessors$1.validator.get = function () {
1834
1855
  if (!this.vm || !this.vm.$validator) {
1835
- return { validate: function () {} };
1856
+ return { validate: function () { return Promise.resolve(true); } };
1836
1857
  }
1837
1858
 
1838
1859
  return this.vm.$validator;
@@ -1960,6 +1981,8 @@ Field.prototype.isWaitingFor = function isWaitingFor (promise) {
1960
1981
  * Updates the field with changed data.
1961
1982
  */
1962
1983
  Field.prototype.update = function update (options) {
1984
+ var this$1 = this;
1985
+
1963
1986
  this.targetOf = options.targetOf || null;
1964
1987
  this.immediate = options.immediate || this.immediate || false;
1965
1988
  this.persist = options.persist || this.persist || false;
@@ -1993,6 +2016,13 @@ Field.prototype.update = function update (options) {
1993
2016
  this.flags.required = this.isRequired;
1994
2017
  }
1995
2018
 
2019
+ if (Object.keys(options.rules || {}).length === 0 && this.updated) {
2020
+ var resetFlag = this.flags.validated;
2021
+ this.validator.validate(("#" + (this.id))).then(function () {
2022
+ this$1.flags.validated = resetFlag;
2023
+ });
2024
+ }
2025
+
1996
2026
  // validate if it was validated before and field was updated and there was a rules mutation.
1997
2027
  if (this.flags.validated && options.rules !== undefined && this.updated) {
1998
2028
  this.validator.validate(("#" + (this.id)));
@@ -4307,6 +4337,10 @@ var ValidationProvider = {
4307
4337
  tag: {
4308
4338
  type: String,
4309
4339
  default: 'span'
4340
+ },
4341
+ slim: {
4342
+ type: Boolean,
4343
+ default: false
4310
4344
  }
4311
4345
  },
4312
4346
  watch: {
@@ -4396,7 +4430,7 @@ var ValidationProvider = {
4396
4430
  /* istanbul ignore next */
4397
4431
  if (!isCallable(slot)) {
4398
4432
  if (process.env.NODE_ENV !== 'production') {
4399
- warn('ValidationProvider expects a scoped slot. Did you forget to add "slot-scope" to your slot?');
4433
+ warn('ValidationProvider expects a scoped slot. Did you forget to add "v-slot" to your slot?');
4400
4434
  }
4401
4435
 
4402
4436
  return h(this.tag, this.$slots.default);
@@ -4408,7 +4442,7 @@ var ValidationProvider = {
4408
4442
  addListeners.call(this$1, input);
4409
4443
  });
4410
4444
 
4411
- return h(this.tag, nodes);
4445
+ return this.slim ? createRenderless(h, nodes) : h(this.tag, nodes);
4412
4446
  },
4413
4447
  beforeDestroy: function beforeDestroy () {
4414
4448
  // cleanup reference.
@@ -4677,7 +4711,7 @@ function updateRenderingContextRefs (ctx) {
4677
4711
 
4678
4712
  // vid was changed.
4679
4713
  if (id !== vid && ctx.$_veeObserver.refs[id] === ctx) {
4680
- ctx.$_veeObserver.unsubscribe(ctx);
4714
+ ctx.$_veeObserver.unsubscribe({ vid: id });
4681
4715
  }
4682
4716
 
4683
4717
  ctx.$_veeObserver.subscribe(ctx);
@@ -4762,12 +4796,17 @@ var ValidationObserver = {
4762
4796
  tag: {
4763
4797
  type: String,
4764
4798
  default: 'span'
4799
+ },
4800
+ slim: {
4801
+ type: Boolean,
4802
+ default: false
4765
4803
  }
4766
4804
  },
4767
4805
  data: function () { return ({
4768
4806
  vid: ("obs_" + (OBSERVER_COUNTER++)),
4769
4807
  refs: {},
4770
4808
  observers: [],
4809
+ persistedStore: {}
4771
4810
  }); },
4772
4811
  computed: {
4773
4812
  ctx: function ctx () {
@@ -4780,7 +4819,7 @@ var ValidationObserver = {
4780
4819
 
4781
4820
  return {
4782
4821
  then: function then (thenable) {
4783
- promise.then(function (success) {
4822
+ return promise.then(function (success) {
4784
4823
  if (success && isCallable(thenable)) {
4785
4824
  return Promise.resolve(thenable());
4786
4825
  }
@@ -4793,7 +4832,14 @@ var ValidationObserver = {
4793
4832
  reset: function () { return this$1.reset(); }
4794
4833
  };
4795
4834
 
4796
- return values(this.refs).concat( this.observers ).reduce(function (acc, provider) {
4835
+ return values(this.refs).concat( Object.keys(this.persistedStore).map(function (key) {
4836
+ return {
4837
+ vid: key,
4838
+ flags: this$1.persistedStore[key].flags,
4839
+ messages: this$1.persistedStore[key].errors
4840
+ };
4841
+ }),
4842
+ this.observers ).reduce(function (acc, provider) {
4797
4843
  Object.keys(flagMergingStrategy).forEach(function (flag) {
4798
4844
  var flags = provider.flags || provider.ctx;
4799
4845
  if (!(flag in acc)) {
@@ -4833,16 +4879,12 @@ var ValidationObserver = {
4833
4879
  }
4834
4880
  },
4835
4881
  render: function render (h) {
4836
- var slots = this.$scopedSlots.default;
4837
- this._persistedStore = this._persistedStore || {};
4838
- if (!isCallable(slots)) {
4839
- return h(this.tag, this.$slots.default);
4882
+ var slots = this.$slots.default || this.$scopedSlots.default || [];
4883
+ if (isCallable(slots)) {
4884
+ slots = slots(this.ctx);
4840
4885
  }
4841
4886
 
4842
- return h(this.tag, {
4843
- on: this.$listeners,
4844
- attrs: this.$attrs
4845
- }, slots(this.ctx));
4887
+ return this.slim ? createRenderless(h, slots) : h(this.tag, { on: this.$listeners, attrs: this.$attrs }, slots);
4846
4888
  },
4847
4889
  methods: {
4848
4890
  subscribe: function subscribe (subscriber, kind) {
@@ -4855,7 +4897,7 @@ var ValidationObserver = {
4855
4897
  }
4856
4898
 
4857
4899
  this.refs = Object.assign({}, this.refs, ( obj = {}, obj[subscriber.vid] = subscriber, obj ));
4858
- if (subscriber.persist && this._persistedStore[subscriber.vid]) {
4900
+ if (subscriber.persist && this.persistedStore[subscriber.vid]) {
4859
4901
  this.restoreProviderState(subscriber);
4860
4902
  }
4861
4903
  },
@@ -4880,15 +4922,22 @@ var ValidationObserver = {
4880
4922
  )).then(function (results) { return results.every(function (r) { return r; }); });
4881
4923
  },
4882
4924
  reset: function reset () {
4925
+ var this$1 = this;
4926
+
4927
+ Object.keys(this.persistedStore).forEach(function (key) {
4928
+ this$1.$delete(this$1.persistedStore, key);
4929
+ });
4883
4930
  return values(this.refs).concat( this.observers).forEach(function (ref) { return ref.reset(); });
4884
4931
  },
4885
4932
  restoreProviderState: function restoreProviderState (provider) {
4886
- var state = this._persistedStore[provider.vid];
4933
+ var state = this.persistedStore[provider.vid];
4887
4934
  provider.setFlags(state.flags);
4888
4935
  provider.applyResult(state);
4889
- delete this._persistedStore[provider.vid];
4936
+ this.$delete(this.persistedStore, provider.vid);
4890
4937
  },
4891
4938
  removeProvider: function removeProvider (vid) {
4939
+ var obj;
4940
+
4892
4941
  var provider = this.refs[vid];
4893
4942
  // save it for the next time.
4894
4943
  if (provider && provider.persist) {
@@ -4899,11 +4948,11 @@ var ValidationObserver = {
4899
4948
  }
4900
4949
  }
4901
4950
 
4902
- this._persistedStore[vid] = {
4903
- flags: provider.flags,
4904
- errors: provider.messages,
4905
- failedRules: provider.failedRules
4906
- };
4951
+ this.persistedStore = assign({}, this.persistedStore, ( obj = {}, obj[vid] = {
4952
+ flags: provider.flags,
4953
+ errors: provider.messages,
4954
+ failedRules: provider.failedRules
4955
+ }, obj ));
4907
4956
  }
4908
4957
 
4909
4958
  this.$delete(this.refs, vid);
@@ -4972,7 +5021,7 @@ function withValidation (component, ctxToProps) {
4972
5021
  return hoc;
4973
5022
  }
4974
5023
 
4975
- var version = '2.2.9';
5024
+ var version = '2.2.13';
4976
5025
  var install = VeeValidate.install;
4977
5026
  var use = VeeValidate.use;
4978
5027
  var setMode = VeeValidate.setMode;
@@ -1,5 +1,5 @@
1
1
  /**
2
- * vee-validate v2.2.9
2
+ * vee-validate v2.2.13
3
3
  * (c) 2019 Abdelrahman Awad
4
4
  * @license MIT
5
5
  */
@@ -34,7 +34,7 @@
34
34
  }
35
35
 
36
36
  // eslint-disable-next-line
37
- return value === value;
37
+ return typeof(value) === 'number' && value !== value;
38
38
  };
39
39
 
40
40
  /**
@@ -767,6 +767,10 @@
767
767
  attributes: {}
768
768
  };
769
769
  }
770
+
771
+ if (!this.container[locale].messages) {
772
+ this.container[locale].messages = {};
773
+ }
770
774
 
771
775
  this.container[locale].messages[key] = message;
772
776
  };
@@ -954,12 +958,15 @@
954
958
  var this$1 = this;
955
959
 
956
960
  var matchesVM = isNullOrUndefined(this.vmId) ? function () { return true; } : function (i) { return i.vmId === this$1.vmId; };
957
- if (isNullOrUndefined(scope)) {
961
+ var matchesScope = function (i) { return i.scope === scope; };
962
+ if (arguments.length === 0) {
963
+ matchesScope = function () { return true; };
964
+ } else if (isNullOrUndefined(scope)) {
958
965
  scope = null;
959
966
  }
960
967
 
961
968
  for (var i = 0; i < this.items.length; ++i) {
962
- if (matchesVM(this.items[i]) && this.items[i].scope === scope) {
969
+ if (matchesVM(this.items[i]) && matchesScope(this.items[i])) {
963
970
  this.items.splice(i, 1);
964
971
  --i;
965
972
  }
@@ -1403,6 +1410,20 @@
1403
1410
  return arr.concat(slots[key]);
1404
1411
  }, []);
1405
1412
  }
1413
+ function createRenderless (h, children) {
1414
+ // Only render the first item of the node.
1415
+ if (Array.isArray(children) && children[0]) {
1416
+ return children[0];
1417
+ }
1418
+
1419
+ // a single node.
1420
+ if (children) {
1421
+ return children;
1422
+ }
1423
+
1424
+ // No slots, render nothing.
1425
+ return h();
1426
+ }
1406
1427
 
1407
1428
  /**
1408
1429
  * Generates the options required to construct a field.
@@ -1828,7 +1849,7 @@
1828
1849
 
1829
1850
  prototypeAccessors$1.validator.get = function () {
1830
1851
  if (!this.vm || !this.vm.$validator) {
1831
- return { validate: function () {} };
1852
+ return { validate: function () { return Promise.resolve(true); } };
1832
1853
  }
1833
1854
 
1834
1855
  return this.vm.$validator;
@@ -1956,6 +1977,8 @@
1956
1977
  * Updates the field with changed data.
1957
1978
  */
1958
1979
  Field.prototype.update = function update (options) {
1980
+ var this$1 = this;
1981
+
1959
1982
  this.targetOf = options.targetOf || null;
1960
1983
  this.immediate = options.immediate || this.immediate || false;
1961
1984
  this.persist = options.persist || this.persist || false;
@@ -1985,6 +2008,13 @@
1985
2008
  this.flags.required = this.isRequired;
1986
2009
  }
1987
2010
 
2011
+ if (Object.keys(options.rules || {}).length === 0 && this.updated) {
2012
+ var resetFlag = this.flags.validated;
2013
+ this.validator.validate(("#" + (this.id))).then(function () {
2014
+ this$1.flags.validated = resetFlag;
2015
+ });
2016
+ }
2017
+
1988
2018
  // validate if it was validated before and field was updated and there was a rules mutation.
1989
2019
  if (this.flags.validated && options.rules !== undefined && this.updated) {
1990
2020
  this.validator.validate(("#" + (this.id)));
@@ -4277,6 +4307,10 @@
4277
4307
  tag: {
4278
4308
  type: String,
4279
4309
  default: 'span'
4310
+ },
4311
+ slim: {
4312
+ type: Boolean,
4313
+ default: false
4280
4314
  }
4281
4315
  },
4282
4316
  watch: {
@@ -4375,7 +4409,7 @@
4375
4409
  addListeners.call(this$1, input);
4376
4410
  });
4377
4411
 
4378
- return h(this.tag, nodes);
4412
+ return this.slim ? createRenderless(h, nodes) : h(this.tag, nodes);
4379
4413
  },
4380
4414
  beforeDestroy: function beforeDestroy () {
4381
4415
  // cleanup reference.
@@ -4644,7 +4678,7 @@
4644
4678
 
4645
4679
  // vid was changed.
4646
4680
  if (id !== vid && ctx.$_veeObserver.refs[id] === ctx) {
4647
- ctx.$_veeObserver.unsubscribe(ctx);
4681
+ ctx.$_veeObserver.unsubscribe({ vid: id });
4648
4682
  }
4649
4683
 
4650
4684
  ctx.$_veeObserver.subscribe(ctx);
@@ -4729,12 +4763,17 @@
4729
4763
  tag: {
4730
4764
  type: String,
4731
4765
  default: 'span'
4766
+ },
4767
+ slim: {
4768
+ type: Boolean,
4769
+ default: false
4732
4770
  }
4733
4771
  },
4734
4772
  data: function () { return ({
4735
4773
  vid: ("obs_" + (OBSERVER_COUNTER++)),
4736
4774
  refs: {},
4737
4775
  observers: [],
4776
+ persistedStore: {}
4738
4777
  }); },
4739
4778
  computed: {
4740
4779
  ctx: function ctx () {
@@ -4747,7 +4786,7 @@
4747
4786
 
4748
4787
  return {
4749
4788
  then: function then (thenable) {
4750
- promise.then(function (success) {
4789
+ return promise.then(function (success) {
4751
4790
  if (success && isCallable(thenable)) {
4752
4791
  return Promise.resolve(thenable());
4753
4792
  }
@@ -4760,7 +4799,14 @@
4760
4799
  reset: function () { return this$1.reset(); }
4761
4800
  };
4762
4801
 
4763
- return values(this.refs).concat( this.observers ).reduce(function (acc, provider) {
4802
+ return values(this.refs).concat( Object.keys(this.persistedStore).map(function (key) {
4803
+ return {
4804
+ vid: key,
4805
+ flags: this$1.persistedStore[key].flags,
4806
+ messages: this$1.persistedStore[key].errors
4807
+ };
4808
+ }),
4809
+ this.observers ).reduce(function (acc, provider) {
4764
4810
  Object.keys(flagMergingStrategy).forEach(function (flag) {
4765
4811
  var flags = provider.flags || provider.ctx;
4766
4812
  if (!(flag in acc)) {
@@ -4800,16 +4846,12 @@
4800
4846
  }
4801
4847
  },
4802
4848
  render: function render (h) {
4803
- var slots = this.$scopedSlots.default;
4804
- this._persistedStore = this._persistedStore || {};
4805
- if (!isCallable(slots)) {
4806
- return h(this.tag, this.$slots.default);
4849
+ var slots = this.$slots.default || this.$scopedSlots.default || [];
4850
+ if (isCallable(slots)) {
4851
+ slots = slots(this.ctx);
4807
4852
  }
4808
4853
 
4809
- return h(this.tag, {
4810
- on: this.$listeners,
4811
- attrs: this.$attrs
4812
- }, slots(this.ctx));
4854
+ return this.slim ? createRenderless(h, slots) : h(this.tag, { on: this.$listeners, attrs: this.$attrs }, slots);
4813
4855
  },
4814
4856
  methods: {
4815
4857
  subscribe: function subscribe (subscriber, kind) {
@@ -4822,7 +4864,7 @@
4822
4864
  }
4823
4865
 
4824
4866
  this.refs = Object.assign({}, this.refs, ( obj = {}, obj[subscriber.vid] = subscriber, obj ));
4825
- if (subscriber.persist && this._persistedStore[subscriber.vid]) {
4867
+ if (subscriber.persist && this.persistedStore[subscriber.vid]) {
4826
4868
  this.restoreProviderState(subscriber);
4827
4869
  }
4828
4870
  },
@@ -4847,24 +4889,31 @@
4847
4889
  )).then(function (results) { return results.every(function (r) { return r; }); });
4848
4890
  },
4849
4891
  reset: function reset () {
4892
+ var this$1 = this;
4893
+
4894
+ Object.keys(this.persistedStore).forEach(function (key) {
4895
+ this$1.$delete(this$1.persistedStore, key);
4896
+ });
4850
4897
  return values(this.refs).concat( this.observers).forEach(function (ref) { return ref.reset(); });
4851
4898
  },
4852
4899
  restoreProviderState: function restoreProviderState (provider) {
4853
- var state = this._persistedStore[provider.vid];
4900
+ var state = this.persistedStore[provider.vid];
4854
4901
  provider.setFlags(state.flags);
4855
4902
  provider.applyResult(state);
4856
- delete this._persistedStore[provider.vid];
4903
+ this.$delete(this.persistedStore, provider.vid);
4857
4904
  },
4858
4905
  removeProvider: function removeProvider (vid) {
4906
+ var obj;
4907
+
4859
4908
  var provider = this.refs[vid];
4860
4909
  // save it for the next time.
4861
4910
  if (provider && provider.persist) {
4862
4911
 
4863
- this._persistedStore[vid] = {
4864
- flags: provider.flags,
4865
- errors: provider.messages,
4866
- failedRules: provider.failedRules
4867
- };
4912
+ this.persistedStore = assign({}, this.persistedStore, ( obj = {}, obj[vid] = {
4913
+ flags: provider.flags,
4914
+ errors: provider.messages,
4915
+ failedRules: provider.failedRules
4916
+ }, obj ));
4868
4917
  }
4869
4918
 
4870
4919
  this.$delete(this.refs, vid);
@@ -4933,7 +4982,7 @@
4933
4982
  return hoc;
4934
4983
  }
4935
4984
 
4936
- VeeValidate.version = '2.2.9';
4985
+ VeeValidate.version = '2.2.13';
4937
4986
  VeeValidate.mapFields = mapFields;
4938
4987
  VeeValidate.ValidationProvider = ValidationProvider;
4939
4988
  VeeValidate.ValidationObserver = ValidationObserver;