Repository: baianat/vee-validate
Pull request #2055 (2019-05-02 22:36:24)

fix: merge dictionary on locale change
🔎 __Overview__

This fix addresses an issue occurring at i18n locale change when you use locale lazy loading.

Because, since the initial merge doesn't have the switched language in memory, it needs to be merged again when the locale change event is received.

codecov[bot]: # [Codecov](https://codecov.io/gh/baianat/vee-validate/pull/2055?src=pr&el=h1) Report
> Merging [#2055](https://codecov.io/gh/baianat/vee-validate/pull/2055?src=pr&el=desc) into [master](https://codecov.io/gh/baianat/vee-validate/commit/fedea704e01aaa64749c04c891b74c1be6d70c12?src=pr&el=desc) will **decrease** coverage by `0.03%`.
> The diff coverage is `50%`.

[![Impacted file tree graph](https://codecov.io/gh/baianat/vee-validate/pull/2055/graphs/tree.svg?width=650&token=XFzlvHKFP5&height=150&src=pr)](https://codecov.io/gh/baianat/vee-validate/pull/2055?src=pr&el=tree)

```diff
@@            Coverage Diff             @@
##           master    #2055      +/-   ##
==========================================
- Coverage   95.97%   95.93%   -0.04%     
==========================================
  Files          62       62              
  Lines        2358     2360       +2     
  Branches      738      739       +1     
==========================================
+ Hits         2263     2264       +1     
- Misses         86       87       +1     
  Partials        9        9
```


| [Impacted Files](https://codecov.io/gh/baianat/vee-validate/pull/2055?src=pr&el=tree) | Coverage Δ | |
|---|---|---|
| [src/plugin.js](https://codecov.io/gh/baianat/vee-validate/pull/2055/diff?src=pr&el=tree#diff-c3JjL3BsdWdpbi5qcw==) | `53.94% <50%> (-0.11%)` | :arrow_down: |

------

[Continue to review full report at Codecov](https://codecov.io/gh/baianat/vee-validate/pull/2055?src=pr&el=continue).
> **Legend** - [Click here to learn more](https://docs.codecov.io/docs/codecov-delta)
> `Δ = absolute <relative> (impact)`, `ø = not affected`, `? = missing data`
> Powered by [Codecov](https://codecov.io/gh/baianat/vee-validate/pull/2055?src=pr&el=footer). Last update [fedea70...77a2259](https://codecov.io/gh/baianat/vee-validate/pull/2055?src=pr&el=lastupdated). Read the [comment docs](https://docs.codecov.io/docs/pull-request-comments).


Patch:
diff --git a/src/plugin.js b/src/plugin.js
index 38309f54..01c95206 100644
--- a/src/plugin.js
+++ b/src/plugin.js
@@ -128,6 +128,10 @@ class VeeValidate {
   _initI18n (config) {
     const { dictionary, i18n, i18nRootKey, locale } = config;
     const onLocaleChanged = () => {
+      if (dictionary) {
+        this.i18nDriver.merge(dictionary);
+      }
+
       this._validator.errors.regenerate();
     };
 
diff --git a/src/rules/decimal.js b/src/rules/decimal.js
index 7613aa02..c86c54ae 100644
--- a/src/rules/decimal.js
+++ b/src/rules/decimal.js
@@ -15,7 +15,7 @@ const validate = (value, { decimals = '*', separator = '.' } = {}) => {
   }
 
   const regexPart = decimals === '*' ? '+' : `{1,${decimals}}`;
-  const regex = new RegExp(`^[-+]?\\d*(\\${separator}\\d${regexPart})?$`);
+  const regex = new RegExp(`^[-+]?\\d*(\\${separator}\\d${regexPart})?([eE]{1}[-]?\\d+)?$`);
 
   if (! regex.test(value)) {
     return false;
diff --git a/types/vee-validate.d.ts b/types/vee-validate.d.ts
index a2e8fc1e..a48ad478 100644
--- a/types/vee-validate.d.ts
+++ b/types/vee-validate.d.ts
@@ -68,8 +68,13 @@ export interface IDictionary {
     setDateFormat(locale: string, format: string): void;
 }
 
+export type ResultObject = {
+    valid: boolean;
+    data?: object;
+}
+
 export interface RuleValidate {
-    (value: any, args: object | any[], data?: any): boolean | Promise<boolean>
+    (value: any, args: object | any[], data?: any): boolean | ResultObject | Promise<boolean | ResultObject>
 }
 
 export interface Rule {


Test patch:
diff --git a/tests/unit/rules/decimal.js b/tests/unit/rules/decimal.js
index 99177dc4..72e62d39 100644
--- a/tests/unit/rules/decimal.js
+++ b/tests/unit/rules/decimal.js
@@ -16,6 +16,10 @@ test('validates numerics with decmial numbers', () => {
   expect(validate('1', { decimails: 0 })).toBe(true);
   expect(validate('+1')).toBe(true);
   expect(validate('+1.2')).toBe(true);
+  expect(validate('1.2E-12')).toBe(true);
+  expect(validate('1.2e16')).toBe(true);
+  expect(validate('1.2E16')).toBe(true);
+  expect(validate('1.2e-12')).toBe(true);
 
   expect(validate('')).toBe(false);
   expect(validate(null)).toBe(false);