DEV Community


Discussion on: Why can't Form Validation be nice?

ealush profile image
Evyatar Alush

Hey, sorry for replying late.

I can see where you're coming from. Yup and other schema validation libraries are great, and there is nothing much you can do with Vest that you can't do with them. They may even do it more concisely.

That's not my argument for using Vest.

You are right, though. Vest is not a perse form validation library, but it is also not a strictly data-model validation library.
It is not a data model validation library since it does not validate the structure of your data. You do not provide a schema to be validated, but instead describe different tests for your data - and the difference between the two is quite large.

If I had to put describe Vest in a sentence I would say something like: "App logic data validations".
The reason for this distinction is simple: Vest does a little more than just validate your data. It also gives you the tools and structure to handle your validations in your feature itself.

An inherent part of every Vest test is the error message displayed to the user upon failure, and since you can write multiple tests for the same field, you can present different error messages per field.

Vest gives you the ability to only validate some fields, for example - only the field that the user currently interacts with.

There are quite a few more features, but the general idea is this - it is not only about the data, but how your validations interact with your feature.

"The annoying part of forms validation is wiring up the actual input and form event handlers without loads of boilerplate, and mapping -- changing an known-good model to/from something the webbrowser elements understand."

So no, Vest is not strictly a form validations library, but working with it on multiple features I did notice the ease of linking a form field to validation test (or tests), and when done correctly, you only need a couple of lines to make your validations work with your inputs and form fields.

I encourage you to take a second look at this file (index.js)

That's really all it takes to make your form validations work with Vest, it's even easier when using a framework such as React or Vue.