Datepicker error
Hello devs
I am encountering a problem with Datepicker
It was working fine but it suddenly returns undefined
anyone encountering the same?
58 Replies
Have you updated to the latest version? v.40? v.39 had some issues with the datepicker. Could be related.
@kennethsese you mean 2.17.40?
Yes
I have 2.17.40 but still not working
something else i should check?
It was working before? Do you know what version of Filament?
I’m actually off to bed…it’s super late here. Hopefully someone can pick this up now, but if not I can take a look when I’m back in the morning.
yes it was working before! my filament version is 2.17.40
sure thanks!
Hi! Did you get resolution on this?
Not yet
Ok...I'll look into it
Thank you @kennethsese this blocked me the whole day 😞
So the datepicker is working on my end. Can you send the code you are using. Also, have you by any chance published your views?
DatePicker::make('from')
->label('starting date')
->minDate(date('Y-m-d', strtotime('+1 day')))
->required()
->placeholder('select the starting date')
->reactive(),
DatePicker::make('to')
->label('ending date')
->required()
->placeholder('select the ending date')
->minDate(function (callable $get) {
$from = $get('from');
if ($from) {
return $from;
}
}),
@kennethsese this is my codes!
I copied pasted that code into my project and everything worked as expected. So it's not the date picker.
Try
npm run build
And have you published your views by any chance?No @kennethsese I didn't
Filament
Installation - Admin Panel - Filament
The elegant TALL stack admin panel for Laravel artisans.
should I run this?
No...I asked about publishing views because if you had published them before then they might not have the latest changes in them which could be causing the problem
It's recommended you DONT publish Filamen't views.
(What you sent was for publishing translations and config files which is fine)
Did
npm run dev
or npm run build
not help?No they didn't 🙁
might this be related to something like node version or php version?
Php no. Node? Probably not.
I’d try the basics:
composer update
php artisan filament:upgrade
And just for sanity I’d check your resources/vendor folder to see if you might have published views by accident.If you are using git, you could try to "rewind" to an earlier commit until it works again. Then go forward to identify where the trouble is coming from.
And then last resort, start up a new project and see if the date picker works there for you.
You need to go through all the normal debug steps since it’s not a problem with the date picker. Strip out all other code in the form. Maybe there’s a conflict with a different plugin. Simply your date picker and see if that solves it. Rewind as suggested above. Start a new project and see if it works there. Unfortunately, it seems to be something with your setup that is very hard to debug from the outside.
You also have 16 console errors but only 1 is shown, something is wrong in your stack could be a plug-in causing it etc, as above debug usual steps
@toeknee_iom here is the full file
Strange that’s for sure
very strange!
what are your casts for 'from' and 'to'?
@awcodes I don't have any casts for them!
So, cast them. I think those fields are expecting a Carbon instance. Based on your code.
That definitely doesn't hurt to try (and they should be cast), but his problem is on create when loading the page
maybe hard refresh and clear broswer cache too.
What’s the column type too? String per chance?
Exactly. @lambertn33 try everything. I mean even turn your computer off and back on again
Maybe it's a weird browser caching thing. Open a new private browser. Try a different browser
they are date!
In the txt file code you provided you are using DateTimePicker which wouldn’t have a date time value from a date column. That would explain the issue too
Well I inserted the Datetimepicker for a while to check if this can work and it failed too!
I give up then 🤣🤣
let me re-clone the repo
@toeknee_iom @toeknee_iom @awcodes the thing is:
I put Datepicker in other filament resource and it worked
but It refused in CampaignResource
This is definitely editing right?
Check the model differences
Try a different browser
What's in your CreateCampaign file?
<?php
namespace App\Filament\Resources\CampaignResource\Pages;
use App\Filament\Resources\CampaignResource;
use App\Models\Campaign;
use App\Models\Province;
use App\Models\Role;
use Filament\Notifications\Notification;
use Filament\Pages\Actions;
use Illuminate\Support\Facades\Auth;
use Filament\Resources\Pages\CreateRecord;
use Illuminate\Support\Str;
class CreateCampaign extends CreateRecord
{
protected static string $resource = CampaignResource::class;
protected function getRedirectUrl(): string
{
return $this->getResource()::getUrl('index');
}
protected function mutateFormDataBeforeCreate(array $data): array
{
$data['id'] = Str::uuid()->toString();
$data['manager_id'] = Auth::user()->manager->id;
$data['district_id'] = Auth::user()->manager->district->id;
$data['province_id'] = Province::where('id', Auth::user()->manager->district->province_id)->value('id');
//draft
$data['from'] = now()->format('Y-m-d');
$data['to'] = now()->format('Y-m-d');
return $data;
}
protected function getCreatedNotification(): ?Notification
{
return Notification::make()
->success()
->title('Campaign registered')
->body('The campaign has been created successfully.');
}
public function mount(): void
{
if (Auth::user()->role->role == Role::DISTRICT_MANAGER_ROLE) {
$check = Campaign::where('manager_id', Auth::user()->manager->id)
->where('status', Campaign::ONGOING)->exists();
abort_unless($check == false, 403);
}
}
}
parent::mount();
you really shouldn't be overriding mount though
you should use the authorization methods to check that.
Confirmed. This is the problem
God bless you so much @awcodes
it is working!
Got the same error
@kennethsese @toeknee_iom thank you so much friends!
How the feck did I miss that! Damn txt files 😂😂 didn’t even see a mount function 🙈
He only sent the Resource file first. Just now sent the CreateCampaign file
@lambertn33 Glad you got it worked out
I was planning on postponing the demo that I have tomorrow lying to be sick😆
Ahh
but you saved my day!
haha!!
Wow! This was critical for you then!
since Yesterday
I was being blocked on this!
now you have to work all night to catch up. lol.
haha sure @awcodes
Thanks for the support guys @awcodes @kennethsese @toeknee_iom @john.77
no worries. good luck with the demo.
Thanks mate!