Toggle fieldsets visibility, but also save hidden data.
My form has a selector with many 'providers'. When selecting a provider, inputs relating to that particular provider are shown. Problem is that I want user to be able to switch between providers, without losing settings for other providers.
What is the most straight-forward way to accomplish this? Simply showing/hiding fieldset doesn't work, because data for hidden fields is not saved.
12 Replies
use
->dehydrate(true)
on hidden fields maybe? Not sure exactly what you're trying to achieve tbhThat's doesn't seem to work. What I'm trying to achieve is basically tabs, but because there are many options I want to display a select instead of tabs.
What do you mean 'it doesn't work' ? Can you give a small example of your code?
So for example like this:
In real life I'm using fieldsets to group multiple inputs, but I've tried a basic version like this as well. When selecting provider1, the provider2_api_key gets cleared when saving.
So you want both
provider1_api_key
and provider2_api_key
to be available when they submit, no matter what they select in the provider
field, right?Exactly
I'm not sure where you use this, but if this is a page, you can try
$this->form->getRawData()
This might not be practical for your use case though
And you might have to filter out other data manually. Not sure if there's a better way to do this tbh. Typical Filament behaviour is to get rid of hidden fields
That being said, it feels like there might be a better solution for what you're trying to do. Forms do have tabs - does that not work for you?
A hacky approach would be to do something like this
but that looks weird hahaYeah I feel like this solution is getting convoluted. Tabs works, but it's not ideal since there are many 'providers' to Select from. Also a Select allows users to search for a specific provider more easily.
A tabs bar would be very wide and practically unusable. But I'm definitly open to other solutions!
Hmm looks like the CSS solution might be what you want? You want the form to be there but hidden - so hide the fieldsets using CSS based on the value of
provider
?Well... it's not pretty but I guess that might be the best solution!
Thanks for thinking with me!
Haha no worries. Look into repeaters/builder - might be a better solution (depending on what you want to achieve)
https://filamentphp.com/docs/3.x/forms/fields/builder
I'll look into it, might be something there!