FormKit: Form building framework for Vue 3
formkit.com
formkit.com
I feel like the next evolution is automatically generating a whole form from selecting a schema in an OpenAPI spec.
In a lot of specs, the type (string, email, phone, int, etc) is present along with any constraints (min/max length). Depending on the language/OpenAPI generator, it even preserves field order. It could massively speed up a lot of the more generic forms that happen in frontend.
Web is almost 30 years old by now, and the announce of a way to make forms relatively easily, still generates an excitement.
I mean, how many more years webdev community needs to realize that typesetting engine from 80s is not a good option for making modern robust UI apps? Technology for making hyperlinked web-pages is a terrible foundation for apps.
Forms are hard because they are (1) pure user input—often textual—, thus inheriting all fundamental difficulties with user input, and (2) arbitrarily reactive such that changing one value may arbitrarily impact other values, e.g. bidirectionally, and (3) you are at the mercy of the platform supporting the input UX that you want to build and you quickly find yourself off the rails otherwise.
This means that even though forms seem like they should be trivial, it's just as hard to generalize over forms as any other UI concept. Or rather, it's not a solved problem for the same reason UI in general isn't a solved problem.
I've done forms with Qt, QML and Flutter, and it's completely different experience.
Cocoa/UIKit are my wheelhouse and have their own share of entry level StackOverflow questions. Though personally I think they make even less sense than the web toolkit. But if you just go by StackOverflow questions, you'd wonder if it was possible to learn anything.
Just search something like "auto layout" on StackOverflow. Turns out that client dev just isn't that easy no matter which abstraction you want to use.
We also built one from scratch and used it in client-facing production applications (Angular + React Native). The biggest hurdle is that JSON schema is great at describing the shape of the form data but not a great job at describing how the form looks. We ended up creating a separate "presentation" schema which handled things like order of the form, rows/columns, widgets to use, and much more.
There's also a number of them out there that generate a form from json schema. I'm most familiar with https://github.com/formschema/native which we use/extend at https://routegy.com for microapps.
Primary author is Justin Schroeder - https://twitter.com/jpschroeder
I help :) (Andrew Boyd) - https://twitter.com/0xBOYD
One note though, I want to point out, that I am able to "break" some of the demo components, like changing type="number" doesn't seem to error the form when I input text over it.
In case one of the other maintainers sees this, I have one other question:
Does this in any way use `eval`? I know a lot of JSON schema validators do, and that is a pain when it comes to CSP. If Formkit doesn't use eval (and maybe we can get a commitment on that...) its a no brainer
As far as I can tell, my go-to schema system doesn’t. https://github.com/colinhacks/zod
Quite a lot of schema validators use `ajv` under the hood. Some, like I believe `yup`, `zod` and `superstruct` do not. I'm not sure why one approach is more advantageous than another, to be honest. I'd think eval would also be a performance issue.
[0]: https://ajv.js.org/security.html#content-security-policy
The schema parser is custom-written and does not make use of `eval`.
Doesn't this happen by default in most cases where a regular <label/> is used?
https://developer.mozilla.org/en-US/docs/Web/HTML/Element/la...
> When a user clicks or touches/taps a label, the browser passes the focus to its associated input (the resulting event is also raised for the input). That increased hit area for focusing the input provides an advantage to anyone trying to activate it — including those using a touch-screen device.
This means you have to somehow hook up into input/validation events for each field, add validation manually and then try to put errors in the right fields even if that is not the last modified field.
Happy to hear if you’re having any issues! We have a very active and helpful discord community.
I'll definitely check this out.
If only all third-party packages/apps were as pleasant to work with as the ones put out by FormKit team.
They definitely are using their DSL for things far out of the scope of JSON schema. The builtin debouncing is pretty neat: https://formkit.com/essentials/validation#debounce-milli
Forms in UI code also tend to have a bunch of business-logic type validation (e.g. "there's already a user with that email address") which schemas alone are unsuitable for.
For example; React has a library to generate forms via JSON Schema and you can use uiSchema feature for the use-case that you mentioned: https://react-jsonschema-form.readthedocs.io/en/latest/api-r...
It's not obvious that's the better direction eh?
It’s all in your browser. You have a debugger at your fingertips.
Why doesn’t Vue stop this from happening? Because it assumes whatever you’re telling it to do is what you want it to do.
0: https://developer.chrome.com/docs/devtools/javascript/breakp...
You can open the browser dev tools on this very page, write in `while(1);`, hit enter and watch the tab freeze up.
The only issue I encountered is that recursive components must be named since they can't import themselves. This is covered in the official Vue docs [3]
[1] https://github.com/AlbinoDrought/vue-dit/blob/master/src/com...
[2] https://albinodrought.github.io/vue-dit/#/sub/technology/uom...
[3] https://v2.vuejs.org/v2/guide/components-edge-cases.html#Rec...