afterStateUpdated() is not working in Datepicker inside livewire components

DatePicker::make('date')
->label('')
->afterStateUpdated(function ($state) {
info($state);
})
->native(false)
->reactive()
->minDate(Carbon::now())
->closeOnDateSelection()
->extraAttributes(['class' => 'date_picker']),
DatePicker::make('date')
->label('')
->afterStateUpdated(function ($state) {
info($state);
})
->native(false)
->reactive()
->minDate(Carbon::now())
->closeOnDateSelection()
->extraAttributes(['class' => 'date_picker']),
this is my code please check when i use tis DatePicker in Normal Resource or widget the afterStateUpdated() is working but not working if i put the same DatePicker inside a Livewire component Form
Solution:
Ok sounds like you haven't filled your component. ensure you have $this->form->fill() on the mount method....
Jump to solution
10 Replies
toeknee
toeknee7mo ago
DatePicker::make('date')
->label('')
->native(false)
->live()
->minDate(Carbon::now())
->closeOnDateSelection()
->extraAttributes(['class' => 'date_picker'])
->afterStateUpdated(function ($state) {
info($state);
}),
DatePicker::make('date')
->label('')
->native(false)
->live()
->minDate(Carbon::now())
->closeOnDateSelection()
->extraAttributes(['class' => 'date_picker'])
->afterStateUpdated(function ($state) {
info($state);
}),
Try this
hello_world
hello_worldOP7mo ago
Thanks But not working
Solution
toeknee
toeknee7mo ago
Ok sounds like you haven't filled your component. ensure you have $this->form->fill() on the mount method.
hello_world
hello_worldOP7mo ago
public function form(Form $form): Form
{
return $form
->statePath('data')
->schema([
Placeholder::make('partnership_name')
->label('')
->extraAttributes(['class' => 'partnership'])
->content(fn ($state) => $this->data['partnership_name']),
Placeholder::make('contact_names')
->label('')
->extraAttributes(['class' => 'contact_names'])
->content(fn ($state) => $this->data['contact_names']),
Placeholder::make('coach_names')
->label('Coach')
->extraAttributes(['class' => 'coach_name'])
->content(fn ($state) => $this->data['coach_names']),
Placeholder::make('created_at')
->label('Creation Date')
->extraAttributes(['class' => 'creation_date'])
->content(function ($state) {
$state = Carbon::parse($this->data['created_at'])->format('d/m/y');
return $state;
}),
DatePicker::make('date')
->label('')
->native(false)
->live()
->minDate(Carbon::now())
->closeOnDateSelection()
->extraAttributes(['class' => 'date_picker'])
->afterStateUpdated(function ($state) {
info($state);
}),
]);
}
public function form(Form $form): Form
{
return $form
->statePath('data')
->schema([
Placeholder::make('partnership_name')
->label('')
->extraAttributes(['class' => 'partnership'])
->content(fn ($state) => $this->data['partnership_name']),
Placeholder::make('contact_names')
->label('')
->extraAttributes(['class' => 'contact_names'])
->content(fn ($state) => $this->data['contact_names']),
Placeholder::make('coach_names')
->label('Coach')
->extraAttributes(['class' => 'coach_name'])
->content(fn ($state) => $this->data['coach_names']),
Placeholder::make('created_at')
->label('Creation Date')
->extraAttributes(['class' => 'creation_date'])
->content(function ($state) {
$state = Carbon::parse($this->data['created_at'])->format('d/m/y');
return $state;
}),
DatePicker::make('date')
->label('')
->native(false)
->live()
->minDate(Carbon::now())
->closeOnDateSelection()
->extraAttributes(['class' => 'date_picker'])
->afterStateUpdated(function ($state) {
info($state);
}),
]);
}
this is my form
toeknee
toeknee7mo ago
And your mount method?
hello_world
hello_worldOP7mo ago
public function mounted(){ $this->form->fill(); }
toeknee
toeknee7mo ago
Wrong
toeknee
toeknee7mo ago
public function mount(): void
{
$this->form->fill();
}
public function mount(): void
{
$this->form->fill();
}
hello_world
hello_worldOP7mo ago
Thank you it's working
Want results from more Discord servers?
Add your server