Date/Time Picker Required
When adding a DatePicker or DateTime Picker to a form (a form on a Livewire component), the
->required()
option isn't ensuring the field is filled out.
The user can still submit the form and null
is submitted on the back end.
Having a similar but worse issue with the Flatpickr plugin (which is why we went back tothe base component) where it always submits null no matter if you pick a date/time or not.
Thanks for any insight!10 Replies
can you share the code?
did.a quick test
this works fine even without the
native
partah just noticed the
"(a form on a Livewire component)"
š
I was testing in a panle
check 'fillable' in the model!
or ->fil(0 in mount?
So I have the models unguarded
Going to post the whole component.
Relevant part:
I have tried just required and also the ->rule('required')
I do have
try
dd($this->form->getState());
Wow
Added your line in above mine and now it works
the validation actually will be triggered when
getState
calledSo do I need to assign the result of getState to my $data variable?
Since right now, clearing data['message'] is how I reset the form input
Appreciate the help! Funny you're the one to respond, We were just looking at your CMS package for another one of our projects.
no, just in your create fun
$data = $this->form->getState();
and use these $data to save your model
It's right there in the "Adding a form to a Livewire component" docs. š
"you can validate and get the form's data using $this->form->getState(). It's important that you use this method instead of accessing the $this->data property directly, because the form's data needs to be validated and transformed into a useful format before being returned"
Definitely worth reading that section.
https://filamentphp.com/docs/3.x/forms/adding-a-form-to-a-livewire-component/#adding-the-form
Look like native(false) cannot use with required()