validation.required error after update filament
Hey guys i have an error after update, i check all my code and at the moment all look ok... i don't see any problem, however in the front, in the form i receive the error message validation.required.
and example of this is a toggle
here is my migration
here is my fillable in the model
and here is my Toogle in my form
however i have this error when i try to save the data

Solution:Jump to solution
Yesterday I had the same problem then and applied as a solution to use cluster, I have a form in which I add or create new categories of services but I got a similar error ... then I checked, checked, found out, used AI, and nothing, it only occurred to me to jump to create the category in a model and resource apart and from there call it in the other resource, but now I see that it persisted in another resource, well the one we saw now ... It is strange if on the one hand because this has not h...
84 Replies
maybe try with
->default('0')
no, i have the same error!
i clear
config:clear
view:clear
cache:clear

and the problem is the same!
Can you show the entire form?
he is the full file bro!
seems fine to me... try to cast
is_closed
as boolean?Yes, I had also done it before but it didn't solve anything either. 👀 😓
sorry, I don't know
don't worry bro, i will fix that... Thanks you
oh I see in your code
->default(0)
but I think it should be a string: ->default("0")
because states are strings in Filamentmmm maybe my problem was that i execute but i forgot the
but wait, do you have the same error if the toggle is on?
yeah, same error if is true or false, or default, i try with a checkbox and the problem was the same!
THAT's weird.
don't you have a mutateBeforeSaveOrSomething method in create or edit page that mutate your data?
no, nothing in create and edit pages
and no mutator in your model, I guess?
here is the model
what the hell...
🤣 😂 so so weird...
For starters you can’t require a Boolean it’s always going to be true or false. Also try ->default(false)
As long as it’s cast correctly it should just work.
Only other thing I can think of is if the views are published and there was an update to them in filament.
Looking at the toggle code though, the default is already false too
@awcodes apparently it fails even if the toggle is on, or with a checkbox, so it's not because of the default value
Checkbox’s can be null ie off will be null, that’s how checkboxes work in forms. Either their value exists or doesn’t in the form data. The toggle is Boolean though. But that’s why I said to try the default() with false instead of the 0, it might be confusing the state and making it indeterminate.
Or just drop the default since it’s already false
it seems it's null in every cases
i try adding a default value, without a default value... with checkbox and the problem or error is the same!
Can you run
php artisan about
and show me the filament section?
On my phone so I can’t look at the files right now.how aver if send like a true i receive the same error

try with a TextInput, and writing in it: is it still null?

good idea
just for test
yeah using a TextInput and sending a '0' like value save without problem!
And do you confirm a simple Toggle gives null?
with no default, dehydrated, or required method
Is there any other fields in the form that could be $setting the state with a live, etc

mmm
maybe the select in users or the Repeater Component when i add a range of time??
To be sure, just keep your toggle, remove the rest of the fields and
dd($data)
into mutateFormDataBeforeCreate()
method in create file like so:
that was my last attempt, good night and good luck! 🙂
Thank you bro, good night there!
I’m not seeing anything unusual in your code. Possibly a caching issue?
you didn't remove the other fields 😉
(just to be sure nothing alter the state)


i clear the cache, restart Docker, delete the binary of laravel octane using frankenphp... i use frankenphp and laravel octane for test my project but this is not a problem... i code with laravel octane more than 3 or 4 months and is the first time that i have this error... can't understand bro
Yea, not adding up to me either, if you have a repo you can share I can pull it down and try it on my machine to see if it’s an octane thing or not.
I don't think it's a problem with the cache either, since using textinput and sending the value as 0 or 1 didn't give me any problems!
It saved without any problems!
On the toggle can you try:
->dehydrateStateUsing(fn($state) => dd($state)) and see if it’s null there.
I don't think it's Octane. In my opinion it's happening somewhere between Alpine and livewire
Nothing bro, same problem!

Certainly could be a bug, but just trying to figure it out. 😀 there is a canFixIndistinctState on when in a repeater which is the only place in the filament code possibly setting it to null.
But typically you have to opt into that behavior.
I would try to dd in afterStateUpdated with live() to see if the value is even changed
Good suggestion. But it should be false out of the gate. Any console errors?
yeah

Click to create from list page and error! 🤷♂️ 😅 😓

Checking the other components the problem persists and is the same.
Hmm, that implies to me that they aren’t being returned with the model

Yea, that’s odd.
livewire.js?id=df3a17f2:3910 Livewire Entangle Error: Livewire property ['data.category_id'] cannot be found on component: ['app.filament.clusters.service-category.resources.service-resource.pages.create-service']
Apparently it goes beyond just the problem with the Toggle
Add parent::mount() inside your CreateService mount() function.
cool
now return me a false
or if i send a true in toggle

the code is like this
Should fix the other errors too.
yes
That's why you have the :fi: in your name! well done.
yes, it's working addding the parent::mount();
Any time you override the mount method you need to also call the parent mount method because it has $this->form->fill() which runs the setup for all the form fields.
That’s why it works.
FYI.
Thank you so much friends, thank you for your time and kindness for help me with this problem...
Thank you for being patient with all the back and forth. Took me a minute to see it.
so, this problem is only because i add the mount() method in my create page?
Yep.
took me 2 hours to not see it 😄
Aaah ok ok, now understand...
It’s ok to override if it’s needed, but the parent does other things too, so if you don’t call it from the override those things will never happen unless you also manually implement them in your override.
In this case the fillForm() method. See https://github.com/filamentphp/filament/blob/3.x/packages/panels/src/Resources/Pages/CreateRecord.php
GitHub
filament/packages/panels/src/Resources/Pages/CreateRecord.php at 3....
A collection of beautiful full-stack components for Laravel. The perfect starting point for your next app. Using Livewire, Alpine.js and Tailwind CSS. - filamentphp/filament
Solution
Yesterday I had the same problem then and applied as a solution to use cluster, I have a form in which I add or create new categories of services but I got a similar error ... then I checked, checked, found out, used AI, and nothing, it only occurred to me to jump to create the category in a model and resource apart and from there call it in the other resource, but now I see that it persisted in another resource, well the one we saw now ... It is strange if on the one hand because this has not happened to me for weeks, until now after having it working for weeks hahahaha maybe the update I did a few days ago deleted cache or something ... I don't know, very strange at the time, but now it is understood why!
i will check all the project and add this parent::
Yea. It’s only needed if you’re extending a livewire component like CreateRecord, EditRecord, etc.
Any Page in filament is the livewire component, so if you’re overriding mount then you want to be sure to call the parent method too.
Unless you are completely overriding it.
It’s also just how OOP works and not necessarily a filament thing or construct.
Understand, thank you so much for the explanation @awcodes
Just glad we figured it out. Now get it shipped. Cheers.🍻