Assign an array to a Forms\Components\Select
How can I assign an array to a Forms\Components\Select? After executing the Action 'refresh_status', the Select options should be set with $statuses.
$statuses has the value:
[
"pending" => "Wachtend op betaling"
"processing" => "In behandeling"
"on-hold" => "In de wacht"
"completed" => "Afgerond"
"cancelled" => "Geannuleerd"
"refunded" => "Terugbetaald"
"failed" => "Mislukt"
"checkout-draft" => "Concept"
]
Solution:Jump to solution
It works! Having
defined in the ListSuppliers makes it work. Thank you so so much for the help!...
23 Replies
Anyone?
You cannot set the values from somewhere else. But you can dynamically set them from the closure:
Thank you @Dennis Koch for your response! So, it's not possible in any way to set the Select options via the hintAction? We need to show a link to fetch the statuses externally if they don't exist in the database yet.
As I said; You cannot set options from some other place. But you can dynamically change the options from within the closure reacting on external changes. Set a property on the livewire component
$loadExternal
or similar and load the options based on thatA little bit off topic, how do i dinamically add an option to be selected based on certain condition?
For example, i have this select form
if a baby is 1 day old, then 'hb0' would be selected
If you want to change the value while changing fields, use
AgeField::make()->afterStateUpdated(fn (Set $set) => $set('imunization', ['hb0']))
thanks, however, i'm looking for way to populate the selected value automatically when opening the form, not when changing any field.
this is my temporary solution
if a baby is 1 day old, then 'hb0' would be selectedI assumed you wanted to react on form input because of this. If you only want a default when creating your "temporary solutions" is good.
alright thanks
I don't quite grasp what you mean, I'm still fairly new to Filament. Do you have an example to help me get started?
I did post an example in my first answer?
Yes but how/where do I need to set the some_property
Wherever you want to trigger the other options to be loaded. In this case in your hintActions
Apologies, I'm not understanding... Here's what I have so far:
Something like this:
Maybe more convenient
See the comment. This belongs on the page. Not the resource. Resources aren't Livewire components
Ah, I see! That's unfortunate... Because it's an action in the table on the resource. So I have to make it an CreatePage/EditPage, right?
If it's on the Table that the page for that is the
ListPage
Solution
It works! Having
defined in the ListSuppliers makes it work. Thank you so so much for the help!