F
Filament8mo ago
nowak

Can someone explain to my why ->dehydrated() works for storing data on disabled fields?

I have been using the ->saveRelationshipsWhenDisabled() method in my Select relationship fields, and it has been a life saver! Now I wanted to mimic this behaviour on a standard TextInput form field, where I found out that adding ->dehydrated() after ->disabled() does exactly that. But after reading the documentation on Field dehydration (https://filamentphp.com/docs/3.x/forms/advanced#field-dehydration) a dozen times, my brain still can't comprehend this concept. Any help understanding this is highly appreciated!
Solution:
->dehydrated() is simply a shorthand for ->dehydrated(true) if you want the field to not be dehydrated you can add ->dehydrated(false) to it. dehydrated(false) in plain English means: "Don't send the data in this form field to the backend php"...
Jump to solution
4 Replies
Solution
miomech
miomech8mo ago
->dehydrated() is simply a shorthand for ->dehydrated(true) if you want the field to not be dehydrated you can add ->dehydrated(false) to it. dehydrated(false) in plain English means: "Don't send the data in this form field to the backend php" From my understanding when a form is "disabled" it is automatically set to ->dehydrated(false).
miomech
miomech8mo ago
To more direcly answer your question if you want the textfield to send the data to the backend even when it's disabled you can simply do
TextInput('my_field')
->disabled()
->dehydrated() // this will force the data to send to the backend, remembere it is the same as ->deydrated(true)


// when you don't want to send data to the backend data simply do
TextInput('my_field')
->disabled() // this will automatically set ->dehyrdated(false) so the data is not sent to the backend
// ->dehyrdated(false) is not needed here.
TextInput('my_field')
->disabled()
->dehydrated() // this will force the data to send to the backend, remembere it is the same as ->deydrated(true)


// when you don't want to send data to the backend data simply do
TextInput('my_field')
->disabled() // this will automatically set ->dehyrdated(false) so the data is not sent to the backend
// ->dehyrdated(false) is not needed here.
nowak
nowakOP8mo ago
Thank you for explaining @miomech!
miomech
miomech8mo ago
No problem my friend
Want results from more Discord servers?
Add your server