Default value in Select input
I want to set one value as default, but the default() is not working. I have had this problem many times. Is there an issue with Select or am I doing something wrong ?
php
Select::make('date_format')
->options([
'm/d/Y' => date('m/d/Y'), // Key is the format, value is the formatted date
'n/j/y' => date('n/j/y'),
'F j, Y' => date('F j, Y'),
'M j, Y' => date('M j, Y'),
])
->default('m/d/Y') // Set the key as the default, which corresponds to the formatted date
->label('Date Format'),
this is my code.17 Replies
Is this on a Create or Edit page?
Note that these defaults are only used when the form is loaded without existing data. Inside panel resources this only works on Create Pages, as Edit Pages will always fill the data from the model.https://filamentphp.com/docs/3.x/forms/fields/getting-started#setting-a-default-value
Create Page
Copied your code an this is what I get.
The default is being set ?
It is not in mine.
What version are you using? Can you run
php artisan about --only=filament
?Can you try upgrading to the latest version and see whether that changes anything?
Sure.
- Upgrading filament/filament (v3.2.92 => v3.2.98)
but still not working
This ia actually not in resource but in page
Could that be causing issues ?
I tried your code. Strange. There's not default set. It's "Select an option" in my.
Yes, it is working in the resource, but not in Page.
Custom page? Can you share the code?
this is my code, This extends settings page, which extends page
Solution
SettingsPage
is not a CreatePage
though. I uses already existing data.If you want to mutate data you need to use the
mutateDataBeforeFill()
hookOhh!! Thanks a lot