F
Filament15mo ago
cakan

Widget with datepicker

I'm trying to make a widget that will be displayed on a Dashboard. Widget displays some statistics based on the selected date. I've created a Widget with a form and added form to the layout, but I'm having trouble how to get date from the form and pass it to my report function. This is my code:
class MonthlyReport extends Widget implements HasForms
{
use InteractsWithForms;

protected static string $view = "filament.resources.user-resource.widgets.monthly-report";

public function getMonthlyReports(): array
{
return ActionHistoryHelper::getReport(Carbon::now()->format('Y-m-d'));
}

public function form(Form $form): Form
{
return $form->schema([DatePicker::make('date')]);
}
}
class MonthlyReport extends Widget implements HasForms
{
use InteractsWithForms;

protected static string $view = "filament.resources.user-resource.widgets.monthly-report";

public function getMonthlyReports(): array
{
return ActionHistoryHelper::getReport(Carbon::now()->format('Y-m-d'));
}

public function form(Form $form): Form
{
return $form->schema([DatePicker::make('date')]);
}
}
View is just displaying the form and the data received from getMonthlyReports function. How do I pass the date value from form to the getMonthlyReports function and refresh the widget?
6 Replies
gigiloouu
gigiloouu4mo ago
did u do it ? i have same problem i want datepicker in my widget
toeknee
toeknee4mo ago
$this->filters
gigiloouu
gigiloouu4mo ago
i try it already but not works
gigiloouu
gigiloouu4mo ago
gigiloouu
gigiloouu4mo ago
this is my code btw like i have widget of chart and i want to top side add date picker and using this date picker this chart will update any ideas?

Did you find this page helpful?