F
Filament3mo 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
miomech3mo 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
miomech3mo 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
nowak3mo ago
Thank you for explaining @miomech!
miomech
miomech2mo ago
No problem my friend
Want results from more Discord servers?
Add your server
More Posts
How to access row data in relationship managerI want to make column visible based on field value but cannot work out what to use? I have tried ->How to set setting values from DB to use accross the project.vat_rate is a value of set in in the DB, where it is a kind of global setting across all classes in How to use $get() to get data from other section or other stepper ?From filament demo : https://github.com/filamentphp/demo/blob/04c41de3dc711cbcb6b4703d9f64e5b3f9f650Call to a member function associate() on nullI got the error like this when tried to create new item or edit seeded data local.ERROR: Call to a SelectFIlter & AsEnumCollectionI have a model `Caliber`. It has a `casts` like this: ```php public function casts(): array { Unable to add Actions Inside Placeholder content of edit modal form.How can I add an action inside Placehoder inside form widget. Here is how I have used Placeholder: PCorrect way to apply a `withCount()` and `->having()` in a SelectFilter?I have a `Domain` that has many `Sites` and I want to filter by the total number of sites each domaiSend data from edit page to create page on a different resource.Im using Laravel v10 and Filament PHP v3 I have the following models: Client LegacyClient I want tWhere documentation From\Components\Group, and what different From\Components\Grid?I need to group fields without labels, and color the background. Should I use Group or Grid? Will thHow to change colors of action buttons/links?There is resource table I need to customize action buttons/links.