foxhound87 / mobx-react-form

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

Async validation runs twice #214

Closed fridays closed 7 years ago

fridays commented 7 years ago

You can see this in the demo, uncomment the console.log statement here: https://github.com/foxhound87/mobx-react-form-demo/blob/master/src/forms/extension/_.async.js#L12

console.log('Loading promised data...');

When the value changes, it happens twice:

Loading promised data...
Loading promised data...

Any ideas?

foxhound87 commented 7 years ago

Noticed it. I will deepen this issue.

foxhound87 commented 7 years ago

This is caused from the nature of the validatorjs passes/fails callbacks:

https://github.com/foxhound87/mobx-react-form/blob/38989a0c292d879be3eaa76e47e065eca6f20cff/src/validators/DVR.js#L89

The package forces to use two calls to the two methods (passes/fails) which is firing the promise 2 time. Maybe I should open an issue on the validatorjs repo.

fridays commented 7 years ago

Oh, that's special! I wonder why it's done like this in validatorjs. Would you better recommend one of the other validation packages?

foxhound87 commented 7 years ago

You can handle async validation with js function (VJF plugin which is enabled by default) and using other DVR rules at the same time if you still want to use validatorjs

fridays commented 7 years ago

Thanks. VJF + chriso's validator work great for me.

foxhound87 commented 7 years ago

Fixed here: https://github.com/foxhound87/mobx-react-form/commit/005d04c7