Dependent select and datatime picker fields.

i have this line of code for setting the value of datatime picker based on selected field Select::make('status') ->searchable() ->options([ 'published' => 'Published', 'draft' => 'Draft', ]) ->live() ->afterStateUpdated(fn (Set $set) => $set('scheduled_at', now())) ->required(), DateTimePicker::make('scheduled_at') ->rules(['date']) ->displayFormat('d-M-Y h:i A') ->minDate(now()) ->required() ->placeholder('Scheduled At'), perticularly it is not working for the datatime picker if there is any alternative please suggest me and i want both the fields to be visible.
2 Replies
Lara Zeus
Lara Zeus13mo ago
try adding ->live() to the DateTimePicker?! not sure tho
Andrew Wallo
Andrew Wallo13mo ago
^If that doesn't work, the DateTimePicker field may just need to be reinitialized so you can try doing this and it may potentially work idk:
Select::make('status')
->searchable()
->options([
'published' => 'Published',
'draft' => 'Draft',
])
->live()
->afterStateUpdated(fn (Set $set) => $set('scheduled_at', now()))
->required(),

DateTimePicker::make('scheduled_at')
->rules(['date'])
->displayFormat('d-M-Y h:i A')
->minDate(now())
->required()
->live()
->placeholder('Scheduled At')
->extraAttributes(['wire:key' => Str::random()]), // Required to reinitialize the datepicker
Select::make('status')
->searchable()
->options([
'published' => 'Published',
'draft' => 'Draft',
])
->live()
->afterStateUpdated(fn (Set $set) => $set('scheduled_at', now()))
->required(),

DateTimePicker::make('scheduled_at')
->rules(['date'])
->displayFormat('d-M-Y h:i A')
->minDate(now())
->required()
->live()
->placeholder('Scheduled At')
->extraAttributes(['wire:key' => Str::random()]), // Required to reinitialize the datepicker
Want results from more Discord servers?
Add your server