Table Filters DatePicker native(false) error
When using DatePicker in Table Filters with native(false), in console returns error:
The code:
Alpine Expression Error: displayText is not defined
Expression: "displayText"
<input id="tableFilters.date.date_from" class="w-full border-none bg-tr…sm:text-sm sm:leading-6" readonly="" placeholder="" wire:key="uzFSJtiB92fiifV63GQ0.tab…DatePicker.display-text" x-model="displayText">
Alpine Expression Error: displayText is not defined
Expression: "displayText"
<input id="tableFilters.date.date_from" class="w-full border-none bg-tr…sm:text-sm sm:leading-6" readonly="" placeholder="" wire:key="uzFSJtiB92fiifV63GQ0.tab…DatePicker.display-text" x-model="displayText">
Filter::make('date')
->form([
DatePicker::make('date_from')
->label('Datums no')
->native(false)
->displayFormat('d.m.Y')
->closeOnDateSelection(true),
DatePicker::make('date_to')
->label('Datums līdz')
->native(false)
->displayFormat('d.m.Y')
->closeOnDateSelection(true),
])
->query(function (Builder $query, array $data): Builder {
return $query
->when(
$data['date_from'],
fn (Builder $query, $date): Builder => $query->whereDate('date', '>=', $date),
)
->when(
$data['date_to'],
fn (Builder $query, $date): Builder => $query->whereDate('date', '<=', $date),
);
})
->indicateUsing(function (array $data): array {
$indicators = [];
if ($data['date_from'] ?? null) {
$indicators['date_from'] = 'Datums no: '.Carbon::parse($data['date_from'])->format('d.m.Y');
}
if ($data['date_to'] ?? null) {
$indicators['date_to'] = 'Datums līdz: '.Carbon::parse($data['date_to'])->format('d.m.Y');
}
return $indicators;
}),
Filter::make('date')
->form([
DatePicker::make('date_from')
->label('Datums no')
->native(false)
->displayFormat('d.m.Y')
->closeOnDateSelection(true),
DatePicker::make('date_to')
->label('Datums līdz')
->native(false)
->displayFormat('d.m.Y')
->closeOnDateSelection(true),
])
->query(function (Builder $query, array $data): Builder {
return $query
->when(
$data['date_from'],
fn (Builder $query, $date): Builder => $query->whereDate('date', '>=', $date),
)
->when(
$data['date_to'],
fn (Builder $query, $date): Builder => $query->whereDate('date', '<=', $date),
);
})
->indicateUsing(function (array $data): array {
$indicators = [];
if ($data['date_from'] ?? null) {
$indicators['date_from'] = 'Datums no: '.Carbon::parse($data['date_from'])->format('d.m.Y');
}
if ($data['date_to'] ?? null) {
$indicators['date_to'] = 'Datums līdz: '.Carbon::parse($data['date_to'])->format('d.m.Y');
}
return $indicators;
}),
2 Replies