foxhound87 / mobx-react-form

Reactive MobX Form State Management
https://foxhound87.github.io/mobx-react-form
MIT License
1.1k stars 129 forks source link

VJF validation rule problem in >=1.37 version #485

Closed evstinik closed 5 years ago

evstinik commented 5 years ago

Hi @foxhound87 Thank you for your nice library.

We've been experiencing some issues with latest versions.

Problem with custom async VJF validation rule. Our code:

import * as validatorjs from 'validatorjs'
...
const validators = {
  'kombinationen[].filter': validatePrNummer
}
const plugins = { dvr: validatorjs }
...
this.form = new Form({ fields, values, labels, rules, placeholders, validators }, { plugins, hooks, options })

Validation function works perfectly in v1.36.3 and earlier, but >= 1.37 we get exception:

72612b552eab18100557.js:2884 Error: The VJF validators functions are defined but no VJF plugin provided. Field: "kombinationen.0.filter".
    at t.checkValidationPlugins (72612b552eab18100557.js:1755)
    at new t (72612b552eab18100557.js:1755)
    at t.makeField (72612b552eab18100557.js:4224)
    at t.initField (72612b552eab18100557.js:4254)
    at Z (72612b552eab18100557.js:28)
    at t.n [as initField] (72612b552eab18100557.js:28)
    at 72612b552eab18100557.js:4254
    at 72612b552eab18100557.js:99
    at Function.pr.forIn (72612b552eab18100557.js:99)
    at t.initFields (72612b552eab18100557.js:4254)

Following the documentation we also tried to initialize vjf by adding it to plugins like this:

const plugins = { dvr: validatorjs, vjf: vjf() }

And got error: Cannot read premises of undefined. Aaand we stuck here. For now we limited version of mobx-react-form to 1.36.3.

Thanks

foxhound87 commented 5 years ago

your plugins should be defined like this:

import dvr from "mobx-react-form/lib/validators/DVR";
import vjf from "mobx-react-form/lib/validators/VJF";
import validatorjs from "validatorjs";

const plugins = {
  vjf: vjf(),
  dvr: dvr(validatorjs)
};

see form.js here https://codesandbox.io/s/rr1kvn07op

foxhound87 commented 5 years ago

can you share a codesandbox which replicates the error?

evstinik commented 5 years ago

My colleague just found out that deleting node modules, reinstalling new version and initializing vjf plugin resolved the issue. Thanks a lot for your time.