Show HN: Form-validation.js – JavaScript form validation library
github.com
github.com
Seriously, this is why I hate modern web development. Absolutely everything seems stuffed full of incredibly over-the-top complexity.
Libraries like jQuery get a lot of hate because they're not trendy or supposedly impact performance too much, but unless you're serving thousands of visitors simultaneously you really should care more about code readability and maintainability than any of that.
At least with something like jQuery validation you can actually understand what the code is doing:
$("#myform").validate({
rules: {
name: "required",
email: {
required: true,
email: true
}
},
messages: {
name: "Please specify your name",
email: {
required: "We need your email address to contact you",
email: "Your email address must be in the format of name@domain.com"
}
}
});But I've seen that it seems to provide APIs on components to deal with validations.
If we just want to validate with route query (which passed from another page and maybe wrong), or validate fields after change page/count, we always need to fill it into form component and then validate it.
Hope this post help you well .
For example json-editor:
https://github.com/json-editor/json-editor
It uses json schema validators that have big toolset available.
Seriously a big part of the problem is to infer type information as you write validators. Anyone can just invent a dsl for type schema. Npm already has heap of these. If we want the schema approach we' probably go with something json-schema based.
Have a look at io-ts and runtypes to see what what a modern js validator should look like (again has something to do with typescript)
> What problem is this resolving
A lot of validation framework doesn't pass `path` (key is not enough in complex situations) to rules to achieve cross-field validation.
> ... these days it is incredibly straightforward.
I've also read HTML5 standard validation APIs, the APIs is not easy to deal with (at least for me). for example, again, do cross-field validation.
> ... polyfill for IE.
Sorry about this, form-validation.js is based on modern javascript feature: Proxy (In order to simulate the data-structure of the form you passed in), There is no possible to provide polyfill for Promise
Hope this helps you well, I'll add some intro to READMD.md when I am free.