vee-validate 2.2.5 → 2.2.9

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.
Files changed (58) hide show
  1. package/dist/locale/ar.js +1 -1
  2. package/dist/locale/az.js +1 -1
  3. package/dist/locale/bg.js +1 -1
  4. package/dist/locale/ca.js +1 -1
  5. package/dist/locale/cs.js +1 -1
  6. package/dist/locale/da.js +1 -1
  7. package/dist/locale/de.js +1 -1
  8. package/dist/locale/el.js +1 -1
  9. package/dist/locale/en.js +1 -1
  10. package/dist/locale/es.js +1 -1
  11. package/dist/locale/et.js +1 -1
  12. package/dist/locale/eu.js +1 -1
  13. package/dist/locale/fa.js +1 -1
  14. package/dist/locale/fi.js +1 -1
  15. package/dist/locale/fr.js +1 -1
  16. package/dist/locale/he.js +1 -1
  17. package/dist/locale/hi.js +1 -1
  18. package/dist/locale/hr.js +1 -1
  19. package/dist/locale/id.js +1 -1
  20. package/dist/locale/it.js +1 -1
  21. package/dist/locale/ja.js +1 -1
  22. package/dist/locale/ka.js +1 -1
  23. package/dist/locale/ko.js +1 -1
  24. package/dist/locale/lt.js +1 -1
  25. package/dist/locale/lv.js +1 -1
  26. package/dist/locale/mn.js +1 -1
  27. package/dist/locale/ms_MY.js +1 -1
  28. package/dist/locale/nb_NO.js +1 -1
  29. package/dist/locale/ne.js +1 -1
  30. package/dist/locale/nl.js +1 -1
  31. package/dist/locale/nn_NO.js +1 -1
  32. package/dist/locale/pl.js +1 -1
  33. package/dist/locale/pt_BR.js +1 -1
  34. package/dist/locale/pt_PT.js +1 -1
  35. package/dist/locale/ro.js +1 -1
  36. package/dist/locale/ru.js +1 -1
  37. package/dist/locale/sk.js +1 -1
  38. package/dist/locale/sl.js +1 -1
  39. package/dist/locale/sq.js +1 -1
  40. package/dist/locale/sr.js +1 -1
  41. package/dist/locale/sr_Latin.js +1 -1
  42. package/dist/locale/sv.js +1 -1
  43. package/dist/locale/th.js +1 -1
  44. package/dist/locale/tr.js +1 -1
  45. package/dist/locale/uk.js +1 -1
  46. package/dist/locale/vi.js +1 -1
  47. package/dist/locale/zh_CN.js +1 -1
  48. package/dist/locale/zh_TW.js +1 -1
  49. package/dist/rules.esm.js +4 -4
  50. package/dist/vee-validate.esm.js +246 -223
  51. package/dist/vee-validate.js +245 -222
  52. package/dist/vee-validate.min.js +1 -1
  53. package/dist/vee-validate.minimal.esm.js +243 -220
  54. package/dist/vee-validate.minimal.js +242 -219
  55. package/dist/vee-validate.minimal.min.js +1 -1
  56. package/package.json +27 -27
  57. package/types/vee-validate.d.ts +14 -3
  58. package/types/vue.d.ts +0 -12
@@ -1,5 +1,5 @@
1
1
  /**
2
- * vee-validate v2.2.5
2
+ * vee-validate v2.2.9
3
3
  * (c) 2019 Abdelrahman Awad
4
4
  * @license MIT
5
5
  */
@@ -1843,7 +1843,7 @@ prototypeAccessors$1.isRequired.get = function () {
1843
1843
  };
1844
1844
 
1845
1845
  prototypeAccessors$1.isDisabled.get = function () {
1846
- return !!(this.componentInstance && this.componentInstance.disabled) || !!(this.el && this.el.disabled);
1846
+ return !!(this.el && this.el.disabled);
1847
1847
  };
1848
1848
 
1849
1849
  /**
@@ -2347,14 +2347,16 @@ Field.prototype.addValueListeners = function addValueListeners () {
2347
2347
  var inputEvent = this._determineInputEvent();
2348
2348
  var events = this._determineEventList(inputEvent);
2349
2349
 
2350
- // if there is a model and an on input validation is requested.
2351
- if (this.model && includes(events, inputEvent)) {
2350
+ // if on input validation is requested.
2351
+ if (includes(events, inputEvent)) {
2352
2352
  var ctx = null;
2353
- var expression = this.model.expression;
2353
+ var expression = null;
2354
+ var watchCtxVm = false;
2354
2355
  // if its watchable from the context vm.
2355
- if (this.model.expression) {
2356
+ if (this.model && this.model.expression) {
2356
2357
  ctx = this.vm;
2357
2358
  expression = this.model.expression;
2359
+ watchCtxVm = true;
2358
2360
  }
2359
2361
 
2360
2362
  // watch it from the custom component vm instead.
@@ -2375,8 +2377,10 @@ Field.prototype.addValueListeners = function addValueListeners () {
2375
2377
  }
2376
2378
  });
2377
2379
 
2378
- // filter out input event as it is already handled by the watcher API.
2379
- events = events.filter(function (e) { return e !== inputEvent; });
2380
+ // filter out input event when we are watching from the context vm.
2381
+ if (watchCtxVm) {
2382
+ events = events.filter(function (e) { return e !== inputEvent; });
2383
+ }
2380
2384
  }
2381
2385
  }
2382
2386
 
@@ -3681,8 +3685,8 @@ Validator.prototype._shouldSkip = function _shouldSkip (field, value) {
3681
3685
  return false;
3682
3686
  }
3683
3687
 
3684
- // disabled fields are skipped
3685
- if (field.isDisabled) {
3688
+ // disabled fields are skipped if useConstraintAttrs is enabled in config
3689
+ if (field.isDisabled && getConfig().useConstraintAttrs) {
3686
3690
  return true;
3687
3691
  }
3688
3692
 
@@ -4073,6 +4077,10 @@ VeeValidate.prototype._initI18n = function _initI18n (config) {
4073
4077
  var i18nRootKey = config.i18nRootKey;
4074
4078
  var locale = config.locale;
4075
4079
  var onLocaleChanged = function () {
4080
+ if (dictionary) {
4081
+ this$1.i18nDriver.merge(dictionary);
4082
+ }
4083
+
4076
4084
  this$1._validator.errors.regenerate();
4077
4085
  };
4078
4086
 
@@ -4224,204 +4232,6 @@ var $validator = null;
4224
4232
 
4225
4233
  var PROVIDER_COUNTER = 0;
4226
4234
 
4227
- function createValidationCtx (ctx) {
4228
- return {
4229
- errors: ctx.messages,
4230
- flags: ctx.flags,
4231
- classes: ctx.classes,
4232
- valid: ctx.isValid,
4233
- failedRules: ctx.failedRules,
4234
- reset: function () { return ctx.reset(); },
4235
- validate: function () {
4236
- var args = [], len = arguments.length;
4237
- while ( len-- ) args[ len ] = arguments[ len ];
4238
-
4239
- return ctx.validate.apply(ctx, args);
4240
- },
4241
- aria: {
4242
- 'aria-invalid': ctx.flags.invalid ? 'true' : 'false',
4243
- 'aria-required': ctx.isRequired ? 'true' : 'false'
4244
- }
4245
- };
4246
- }
4247
-
4248
- function normalizeValue$1 (value) {
4249
- if (isEvent(value)) {
4250
- return value.target.type === 'file' ? toArray(value.target.files) : value.target.value;
4251
- }
4252
-
4253
- return value;
4254
- }
4255
-
4256
- /**
4257
- * Determines if a provider needs to run validation.
4258
- */
4259
- function shouldValidate (ctx, model) {
4260
- // when an immediate/initial validation is needed and wasn't done before.
4261
- if (!ctx._ignoreImmediate && ctx.immediate) {
4262
- return true;
4263
- }
4264
-
4265
- // when the value changes for whatever reason.
4266
- if (ctx.value !== model.value) {
4267
- return true;
4268
- }
4269
-
4270
- // when it needs validation due to props/cross-fields changes.
4271
- if (ctx._needsValidation) {
4272
- return true;
4273
- }
4274
-
4275
- // when the initial value is undefined and the field wasn't rendered yet.
4276
- if (!ctx.initialized && model.value === undefined) {
4277
- return true;
4278
- }
4279
-
4280
- return false;
4281
- }
4282
-
4283
- function computeModeSetting (ctx) {
4284
- var compute = isCallable(ctx.mode) ? ctx.mode : modes[ctx.mode];
4285
-
4286
- return compute({
4287
- errors: ctx.messages,
4288
- value: ctx.value,
4289
- flags: ctx.flags
4290
- });
4291
- }
4292
-
4293
- function onRenderUpdate (model) {
4294
- if (!this.initialized) {
4295
- this.initialValue = model.value;
4296
- }
4297
-
4298
- var validateNow = shouldValidate(this, model);
4299
- this._needsValidation = false;
4300
- this.value = model.value;
4301
- this._ignoreImmediate = true;
4302
-
4303
- if (!validateNow) {
4304
- return;
4305
- }
4306
-
4307
- this.validateSilent().then(this.immediate || this.flags.validated ? this.applyResult : function (x) { return x; });
4308
- }
4309
-
4310
- // Creates the common handlers for a validatable context.
4311
- function createCommonHandlers (ctx) {
4312
- var onInput = function (e) {
4313
- ctx.syncValue(e); // track and keep the value updated.
4314
- ctx.setFlags({ dirty: true, pristine: false });
4315
- };
4316
-
4317
- // Blur event listener.
4318
- var onBlur = function () {
4319
- ctx.setFlags({ touched: true, untouched: false });
4320
- };
4321
-
4322
- var onValidate = ctx.$veeHandler;
4323
- var mode = computeModeSetting(ctx);
4324
-
4325
- // Handle debounce changes.
4326
- if (!onValidate || ctx.$veeDebounce !== ctx.debounce) {
4327
- onValidate = debounce(
4328
- function () {
4329
- ctx.$nextTick(function () {
4330
- var pendingPromise = ctx.validateSilent();
4331
- // avoids race conditions between successive validations.
4332
- ctx._pendingValidation = pendingPromise;
4333
- pendingPromise.then(function (result) {
4334
- if (pendingPromise === ctx._pendingValidation) {
4335
- ctx.applyResult(result);
4336
- ctx._pendingValidation = null;
4337
- }
4338
- });
4339
- });
4340
- },
4341
- mode.debounce || ctx.debounce
4342
- );
4343
-
4344
- // Cache the handler so we don't create it each time.
4345
- ctx.$veeHandler = onValidate;
4346
- // cache the debounce value so we detect if it was changed.
4347
- ctx.$veeDebounce = ctx.debounce;
4348
- }
4349
-
4350
- return { onInput: onInput, onBlur: onBlur, onValidate: onValidate };
4351
- }
4352
-
4353
- // Adds all plugin listeners to the vnode.
4354
- function addListeners (node) {
4355
- var model = findModel(node);
4356
- // cache the input eventName.
4357
- this._inputEventName = this._inputEventName || getInputEventName(node, model);
4358
-
4359
- onRenderUpdate.call(this, model);
4360
-
4361
- var ref = createCommonHandlers(this);
4362
- var onInput = ref.onInput;
4363
- var onBlur = ref.onBlur;
4364
- var onValidate = ref.onValidate;
4365
- addVNodeListener(node, this._inputEventName, onInput);
4366
- addVNodeListener(node, 'blur', onBlur);
4367
-
4368
- // add the validation listeners.
4369
- this.normalizedEvents.forEach(function (evt) {
4370
- addVNodeListener(node, evt, onValidate);
4371
- });
4372
-
4373
- this.initialized = true;
4374
- }
4375
-
4376
- function createValuesLookup (ctx) {
4377
- var providers = ctx.$_veeObserver.refs;
4378
-
4379
- return ctx.fieldDeps.reduce(function (acc, depName) {
4380
- if (!providers[depName]) {
4381
- return acc;
4382
- }
4383
-
4384
- acc[depName] = providers[depName].value;
4385
-
4386
- return acc;
4387
- }, {});
4388
- }
4389
-
4390
- function updateRenderingContextRefs (ctx) {
4391
- // IDs should not be nullable.
4392
- if (isNullOrUndefined(ctx.id) && ctx.id === ctx.vid) {
4393
- ctx.id = PROVIDER_COUNTER;
4394
- PROVIDER_COUNTER++;
4395
- }
4396
-
4397
- var id = ctx.id;
4398
- var vid = ctx.vid;
4399
- // Nothing has changed.
4400
- if (ctx.isDeactivated || (id === vid && ctx.$_veeObserver.refs[id])) {
4401
- return;
4402
- }
4403
-
4404
- // vid was changed.
4405
- if (id !== vid && ctx.$_veeObserver.refs[id] === ctx) {
4406
- ctx.$_veeObserver.unsubscribe(ctx);
4407
- }
4408
-
4409
- ctx.$_veeObserver.subscribe(ctx);
4410
- ctx.id = vid;
4411
- }
4412
-
4413
- function createObserver () {
4414
- return {
4415
- refs: {},
4416
- subscribe: function subscribe (ctx) {
4417
- this.refs[ctx.vid] = ctx;
4418
- },
4419
- unsubscribe: function unsubscribe (ctx) {
4420
- delete this.refs[ctx.vid];
4421
- }
4422
- };
4423
- }
4424
-
4425
4235
  var ValidationProvider = {
4426
4236
  $__veeInject: false,
4427
4237
  inject: {
@@ -4526,19 +4336,10 @@ var ValidationProvider = {
4526
4336
  var this$1 = this;
4527
4337
 
4528
4338
  var rules = normalizeRules(this.rules);
4529
- var providers = this.$_veeObserver.refs;
4530
4339
 
4531
4340
  return Object.keys(rules).filter(RuleContainer.isTargetRule).map(function (rule) {
4532
4341
  var depName = rules[rule][0];
4533
- var watcherName = "$__" + depName;
4534
- if (!isCallable(this$1[watcherName]) && providers[depName]) {
4535
- this$1[watcherName] = providers[depName].$watch('value', function () {
4536
- if (this$1.flags.validated) {
4537
- this$1._needsValidation = true;
4538
- this$1.validate();
4539
- }
4540
- });
4541
- }
4342
+ watchCrossFieldDep(this$1, depName);
4542
4343
 
4543
4344
  return depName;
4544
4345
  });
@@ -4697,6 +4498,228 @@ var ValidationProvider = {
4697
4498
  }
4698
4499
  };
4699
4500
 
4501
+ function createValidationCtx (ctx) {
4502
+ return {
4503
+ errors: ctx.messages,
4504
+ flags: ctx.flags,
4505
+ classes: ctx.classes,
4506
+ valid: ctx.isValid,
4507
+ failedRules: ctx.failedRules,
4508
+ reset: function () { return ctx.reset(); },
4509
+ validate: function () {
4510
+ var args = [], len = arguments.length;
4511
+ while ( len-- ) args[ len ] = arguments[ len ];
4512
+
4513
+ return ctx.validate.apply(ctx, args);
4514
+ },
4515
+ aria: {
4516
+ 'aria-invalid': ctx.flags.invalid ? 'true' : 'false',
4517
+ 'aria-required': ctx.isRequired ? 'true' : 'false'
4518
+ }
4519
+ };
4520
+ }
4521
+
4522
+ function normalizeValue$1 (value) {
4523
+ if (isEvent(value)) {
4524
+ return value.target.type === 'file' ? toArray(value.target.files) : value.target.value;
4525
+ }
4526
+
4527
+ return value;
4528
+ }
4529
+
4530
+ /**
4531
+ * Determines if a provider needs to run validation.
4532
+ */
4533
+ function shouldValidate (ctx, model) {
4534
+ // when an immediate/initial validation is needed and wasn't done before.
4535
+ if (!ctx._ignoreImmediate && ctx.immediate) {
4536
+ return true;
4537
+ }
4538
+
4539
+ // when the value changes for whatever reason.
4540
+ if (ctx.value !== model.value) {
4541
+ return true;
4542
+ }
4543
+
4544
+ // when it needs validation due to props/cross-fields changes.
4545
+ if (ctx._needsValidation) {
4546
+ return true;
4547
+ }
4548
+
4549
+ // when the initial value is undefined and the field wasn't rendered yet.
4550
+ if (!ctx.initialized && model.value === undefined) {
4551
+ return true;
4552
+ }
4553
+
4554
+ return false;
4555
+ }
4556
+
4557
+ function computeModeSetting (ctx) {
4558
+ var compute = isCallable(ctx.mode) ? ctx.mode : modes[ctx.mode];
4559
+
4560
+ return compute({
4561
+ errors: ctx.messages,
4562
+ value: ctx.value,
4563
+ flags: ctx.flags
4564
+ });
4565
+ }
4566
+
4567
+ function onRenderUpdate (model) {
4568
+ if (!this.initialized) {
4569
+ this.initialValue = model.value;
4570
+ }
4571
+
4572
+ var validateNow = shouldValidate(this, model);
4573
+ this._needsValidation = false;
4574
+ this.value = model.value;
4575
+ this._ignoreImmediate = true;
4576
+
4577
+ if (!validateNow) {
4578
+ return;
4579
+ }
4580
+
4581
+ this.validateSilent().then(this.immediate || this.flags.validated ? this.applyResult : function (x) { return x; });
4582
+ }
4583
+
4584
+ // Creates the common handlers for a validatable context.
4585
+ function createCommonHandlers (ctx) {
4586
+ var onInput = function (e) {
4587
+ ctx.syncValue(e); // track and keep the value updated.
4588
+ ctx.setFlags({ dirty: true, pristine: false });
4589
+ };
4590
+
4591
+ // Blur event listener.
4592
+ var onBlur = function () {
4593
+ ctx.setFlags({ touched: true, untouched: false });
4594
+ };
4595
+
4596
+ var onValidate = ctx.$veeHandler;
4597
+ var mode = computeModeSetting(ctx);
4598
+
4599
+ // Handle debounce changes.
4600
+ if (!onValidate || ctx.$veeDebounce !== ctx.debounce) {
4601
+ onValidate = debounce(
4602
+ function () {
4603
+ ctx.$nextTick(function () {
4604
+ var pendingPromise = ctx.validateSilent();
4605
+ // avoids race conditions between successive validations.
4606
+ ctx._pendingValidation = pendingPromise;
4607
+ pendingPromise.then(function (result) {
4608
+ if (pendingPromise === ctx._pendingValidation) {
4609
+ ctx.applyResult(result);
4610
+ ctx._pendingValidation = null;
4611
+ }
4612
+ });
4613
+ });
4614
+ },
4615
+ mode.debounce || ctx.debounce
4616
+ );
4617
+
4618
+ // Cache the handler so we don't create it each time.
4619
+ ctx.$veeHandler = onValidate;
4620
+ // cache the debounce value so we detect if it was changed.
4621
+ ctx.$veeDebounce = ctx.debounce;
4622
+ }
4623
+
4624
+ return { onInput: onInput, onBlur: onBlur, onValidate: onValidate };
4625
+ }
4626
+
4627
+ // Adds all plugin listeners to the vnode.
4628
+ function addListeners (node) {
4629
+ var model = findModel(node);
4630
+ // cache the input eventName.
4631
+ this._inputEventName = this._inputEventName || getInputEventName(node, model);
4632
+
4633
+ onRenderUpdate.call(this, model);
4634
+
4635
+ var ref = createCommonHandlers(this);
4636
+ var onInput = ref.onInput;
4637
+ var onBlur = ref.onBlur;
4638
+ var onValidate = ref.onValidate;
4639
+ addVNodeListener(node, this._inputEventName, onInput);
4640
+ addVNodeListener(node, 'blur', onBlur);
4641
+
4642
+ // add the validation listeners.
4643
+ this.normalizedEvents.forEach(function (evt) {
4644
+ addVNodeListener(node, evt, onValidate);
4645
+ });
4646
+
4647
+ this.initialized = true;
4648
+ }
4649
+
4650
+ function createValuesLookup (ctx) {
4651
+ var providers = ctx.$_veeObserver.refs;
4652
+
4653
+ return ctx.fieldDeps.reduce(function (acc, depName) {
4654
+ if (!providers[depName]) {
4655
+ return acc;
4656
+ }
4657
+
4658
+ acc[depName] = providers[depName].value;
4659
+
4660
+ return acc;
4661
+ }, {});
4662
+ }
4663
+
4664
+ function updateRenderingContextRefs (ctx) {
4665
+ // IDs should not be nullable.
4666
+ if (isNullOrUndefined(ctx.id) && ctx.id === ctx.vid) {
4667
+ ctx.id = PROVIDER_COUNTER;
4668
+ PROVIDER_COUNTER++;
4669
+ }
4670
+
4671
+ var id = ctx.id;
4672
+ var vid = ctx.vid;
4673
+ // Nothing has changed.
4674
+ if (ctx.isDeactivated || (id === vid && ctx.$_veeObserver.refs[id])) {
4675
+ return;
4676
+ }
4677
+
4678
+ // vid was changed.
4679
+ if (id !== vid && ctx.$_veeObserver.refs[id] === ctx) {
4680
+ ctx.$_veeObserver.unsubscribe(ctx);
4681
+ }
4682
+
4683
+ ctx.$_veeObserver.subscribe(ctx);
4684
+ ctx.id = vid;
4685
+ }
4686
+
4687
+ function createObserver () {
4688
+ return {
4689
+ refs: {},
4690
+ subscribe: function subscribe (ctx) {
4691
+ this.refs[ctx.vid] = ctx;
4692
+ },
4693
+ unsubscribe: function unsubscribe (ctx) {
4694
+ delete this.refs[ctx.vid];
4695
+ }
4696
+ };
4697
+ }
4698
+
4699
+ function watchCrossFieldDep (ctx, depName, withHooks) {
4700
+ if ( withHooks === void 0 ) withHooks = true;
4701
+
4702
+ var providers = ctx.$_veeObserver.refs;
4703
+ if (!ctx._veeWatchers) {
4704
+ ctx._veeWatchers = {};
4705
+ }
4706
+
4707
+ if (!providers[depName] && withHooks) {
4708
+ return ctx.$once('hook:mounted', function () {
4709
+ watchCrossFieldDep(ctx, depName, false);
4710
+ });
4711
+ }
4712
+
4713
+ if (!isCallable(ctx._veeWatchers[depName]) && providers[depName]) {
4714
+ ctx._veeWatchers[depName] = providers[depName].$watch('value', function () {
4715
+ if (ctx.flags.validated) {
4716
+ ctx._needsValidation = true;
4717
+ ctx.validate();
4718
+ }
4719
+ });
4720
+ }
4721
+ }
4722
+
4700
4723
  var flagMergingStrategy = {
4701
4724
  pristine: 'every',
4702
4725
  dirty: 'some',
@@ -4949,7 +4972,7 @@ function withValidation (component, ctxToProps) {
4949
4972
  return hoc;
4950
4973
  }
4951
4974
 
4952
- var version = '2.2.5';
4975
+ var version = '2.2.9';
4953
4976
  var install = VeeValidate.install;
4954
4977
  var use = VeeValidate.use;
4955
4978
  var setMode = VeeValidate.setMode;
@@ -4961,4 +4984,4 @@ VeeValidate.ValidationObserver = ValidationObserver;
4961
4984
  VeeValidate.withValidation = withValidation;
4962
4985
 
4963
4986
  export default VeeValidate;
4964
- export { install, use, setMode, directive, mixin, mapFields, Validator, ErrorBag, version, ValidationProvider, ValidationObserver, withValidation };
4987
+ export { ErrorBag, ValidationObserver, ValidationProvider, Validator, directive, install, mapFields, mixin, setMode, use, version, withValidation };