F
Filament9mo ago
Emaz

Hydration on Select

Can anyone think of a reason why my Select would not hydrate on edit? Select::make('priority') ->options([ '1' => '1. Urgent', '2' => '2. Easy', '3' => '3. Short Term', '4' => '4. Long Term', ]) ->afterStateHydrated(function ($state, Forms\Set $set, Forms\Get $get) { \Log::info($state); }), My ToDo model does have a mutator but I made sure the Select options match. public function getPriorityAttribute($value) { $options = [ '1' => '1. Urgent', '2' => '2. Easy', '3' => '3. Short Term', '4' => '4. Long Term', ]; return $options[$value] ?? $value; } Everything is working fine, just that when editing a record the Select doesn't hydrate so it says "Please select an option" instead of whatever data has been saved.
Solution:
So this was an issue with the mutator getting in the way. I was using a mutator because I needed something sortable for groups. This is task manager so I resorted to group names like "1. Urgent" so they'd sort. I needed not the rows to sort but the groups. In the end I got rid of the mutator and just kept the priority text string throughout. The mutator WAS getting in the way of hydrating the Select. I'm doing a task thingy cause I think all 5.4 million of them out there are bloated. LOL...
No description
Jump to solution
1 Reply
Solution
Emaz
Emaz9mo ago
So this was an issue with the mutator getting in the way. I was using a mutator because I needed something sortable for groups. This is task manager so I resorted to group names like "1. Urgent" so they'd sort. I needed not the rows to sort but the groups. In the end I got rid of the mutator and just kept the priority text string throughout. The mutator WAS getting in the way of hydrating the Select. I'm doing a task thingy cause I think all 5.4 million of them out there are bloated. LOL
No description