Render form elements based on selection (dynamically)
Hi! I'm using the Form Builder standalone but I have a question regarding rendering. My Livewire component now has this:
My Form schema looks like this:
But based of the selected vault I want to load a form form the belonging vault class. That whole formset should become value as a array.
Please let me know if you need more info
17 Replies
Where is your selected Vault
Where do you choose the Vault?
You are looking for "dependant fields". Check the docs.
Somewhat depended fields yea but it should not be hooked up in that forms array. Cause this will allow you to essentially add credentials. But I can have 100 providers with different fields
So that array will be used. So when x is selected I want to retrieve the fields and add them in the form. Those fields is a Key Value array that makes up the value
Not sure if this is possible without adding them all into the form and showing/hiding them based on the Select. Maybe use a wizard instead and show them in step2?
At some point you need to add it into the form schema.
Mmm that might be a option. Ill have a look
I did something similar here with Templates. But it requires all the possible options to be in the form:
https://filamentphp.com/tricks/template-based-forms
Filament
Template based forms by Dennis Koch - Tricks - Filament
Filament is a collection of tools for rapidly building beautiful TALL stack apps, designed for humans.
Ill have a look at that as well thanks for the suggestion π hopefully I find my best way
Love the great support always
i wrote about this the other day - https://github.com/filamentphp/filament/blob/3.x/packages/forms/docs/08-advanced.md#dynamic-fields-based-on-a-select-option
GitHub
filament/08-advanced.md at 3.x Β· filamentphp/filament
Admin panel, form builder and table builder for Laravel. Built with the TALL stack. Designed for humans. - filament/08-advanced.md at 3.x Β· filamentphp/filament
it'll be in the v3 docs
mutateFormDataBeforeFill && mutateFormDataBeforeSave
Are only in filament admin right? What is the way todo so with forms?
theres no need outside of the admin
as you have full control over the data array before it is saved to the model
I see but how does it work? Cause I know get
And I do not do anything except dumping
Maybe I missunderstand something
Everything in that group should be key-value under the key
value
Nvm, I think I got it now π
$this->form->getState()
dont forget $this->form->fill()
in mount, it is required.I see yea, I'm almost there π