JsonToForm + LiveComponent #2894
Closed
cabillama-anaxago
started this conversation in
Symfony UX Showcase
Replies: 1 comment
-
Oups, can someone delete this post? I've reposted it with my personal account so I can follow it easily. |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
Hi everyone!
I'd like to showcase a project I'm working on. I believe it would help other developers.
I've come to many struggles building forms in the past. I've also seen that we duplicate a lot of things when it comes to building forms, rendering them, managing display dependencies, saving data...
So I decided to extract all that logic into an open-source bundle called ambelz/json-to-form.
With it, a single JSON file fully describes your form — sections, categories, questions, constraints, even conditional visibility (not entirely managed at the moment, but simple conditions work). The bundle’s JsonToFormTransformer turns that JSON into a ready-to-use Symfony 7 FormBuilder, while QuestionConditionEvaluator handles all the “show/hide this field when…” rules for you.
The JSON looks like this:

For a reactive UX, I wrap the generated form in a Symfony UX Live Component. Whenever a user changes a value, the component re-evaluates the conditions server-side and re-renders only the affected fields. Draft submissions are auto-saved, then finalized and sent to external APIs once validated. Almost every Symfony form Type is managed out of the box (even Uploads: you handle the file via your LiveComponent). However, I still have work to do : Collections (repeatable), DropZone, form design options, translations...
The result could look like this on your own project:

If building complex, dynamic forms is part of your daily pain, give ambelz/json-to-form a try and let me know what you think!
Also, I believe it could be great to have this kind of tool inside Symfony UX. Forms are at the heart of today's web and I've heard too many times that Symfony can't build nice forms...
Thanks for your feedbacks!
Beta Was this translation helpful? Give feedback.
All reactions