How to generate fields dynamically?
Hello,
I would like to make a form in which fields are generated according to a value selected in a Select.
I would like to be able to select the activity in a drop down list, then the list of packages (name of the package + textinput with the number) is displayed. How can I do this?
I would like a very clean display, so I would like if possible not to have to use a repeater but rather something like a foreach loop (but I don't know how to get the data from the current record in the form() function)
11 Replies
GitHub
GitHub - danharrin/form-builder: A demo of how to use filament/form...
A demo of how to use filament/forms to build a user-facing Form Builder which stores fields in JSON. - GitHub - danharrin/form-builder: A demo of how to use filament/forms to build a user-facing Fo...
Ok thanks... but is there anything similar to what I am looking for in this repository?
I don't really understand how I can implement what I want based on this :/
Unknown User•2y ago
Message Not Public
Sign In & Join Server To View
Thank you. Is it possible to have a little more explanation please? I can imagine that the answer is probably in your repositories but I don't see it.
So you don't want to create them dynamically really? You want a static set of fields based on a selected set correct?
In your example, the fields are all generated but only displayed if the correct template is selected. In my case I can't do that because my package table is very large. So I have to generate only the related fields.
Yes, I would like to generate some fields based on a selection in the add/edit form
So by default the builder lets you add fields dynamically as individual fields from a drop down.
You look like you want to build out the set of data from a selection, so for that I would build all the fields, then conditionally render them based on the selection within a function.
Ok so if I have 200 activities with 5 packages for each of them, I have to generate on each add/edit page 1000 fields and display only the 5 I need?
You don't have too at all. You could render them based off your storage. AS Johnny shared you can see how you can render fields from a json string. So you can store your fieldset as json data and then decode it and map it with the form builder render.
You can see how dan has done it here:
https://github.com/danharrin/form-builder
and then renders in the frontend
GitHub
GitHub - danharrin/form-builder: A demo of how to use filament/form...
A demo of how to use filament/forms to build a user-facing Form Builder which stores fields in JSON. - GitHub - danharrin/form-builder: A demo of how to use filament/forms to build a user-facing Fo...
I will try. Thank you