Closed bryantgillespie closed 3 months ago
Here is a very good implementation in vue: https://jsonforms.io/
@romhml could I ask your opinion on this?
Implementing a form builder / custom json validation rules falls out of the scope of a component library like nuxt/ui. However, you can achieve these functionalities using Nuxt UI components. Here's a basic example to get you started: https://stackblitz.com/edit/nuxt-ui-apnozj
State management (especially for nested structures)
Managing nested form state can be tricky, but the next Nuxt UI version will include built-in nested forms for easier handling. See a preview here: https://github.com/benjamincanac/ui3/blob/dev/playground/components/FormNestedExample.vue
Description
Would be awesome if you could pass a JSON schema for the
<Form>
component and dynamically generate and render the form.Why?
When working with a Nuxt project that's connected to a headless CMS or other backend - non-dev users often have a need to create and render forms on the frontend. Implementing a new form either requires:
A) developer to code it up which obviously takes a lot of time and needs to happen for each new form added to the site / app
or
B) the non-dev to build it in a third party tool like Typeform, Jotform, and others - and then embed it in the page / content. This could break the layout or function of the app / site and also requires adding another dependency / tool to the project.
Neither of these is really ideal for basic form use cases (contact information, lead generation, client intake)
Must haves
Here's an example schema for a form.
Nice To Haves
Gotchas
Notes
I'm using dynamic form generation in this project https://github.com/directus-community/agency-os/blob/main/components/base/VForm.vue
But currently through another library.
Example
@benjamincanac put together a quick example of how this might be possible here. https://stackblitz.com/edit/nuxt-ui-zjzjmm?file=components%2FFormCustom.ts
Additional context
Examples of Editing Forms with a Headless CMS (Directus in this case)