Reactive field inside a dynamic generated schema Filament v3
I have a schema that is generated dynamicly like so based on a selected field
And the
$this->defectListSchema
contains many fields like this
But when i type anything in the numberOfDefects
field that is reactive the entire form goes blank, disappears.
What could be the problem ?16 Replies
That doesn't smell right. Seems like you are running reactive code out of a field on a schema in a property that get blown away during the update?
something like that yes
but that is the problem that the fields are dynamicly generated after a Select is selected
Can't quite put my finger on it, but looks wrong. You are creating the dynamic schema in $this->defectListSchema, and code within that fires on reactive, but then that property with the code in it gets recreated underneath it.
yes
that is the problem
Which I suspect confuses the hell out of the execution stack.
the other option that i tough of was to generate all of the fields and hide the ones that are not associated with the selected Select
but that will result in a massive schema
I just don't think it will work the way you are trying to do it.
So how should you suggest i generate a schema based on the selected Select option ?
And make a field inside of that generated schema be reactive so i can run a couple of checks and coloring it before it is saved in the DB ?
i did find in the docs that you could do a Custom Fields but don't know if that will work
Just apply visible() to the fields / sections / groups, with a closure that $get's the value of the select.
but wont that result in a massive schema ?
No idea, as I don't know what you are trying to render.
I have a list of defects where 1 defect may be in more than 1 stage
the stages are 4 in total
the defects are 33 in total
Some defects may or may not be applied on a current stage but most of them are
So to make it like this i will have to write down in the schema almost 100 fields/sections and each to be
hidden()
based on the selected stage
That will work but i don't think is the best course of action
so thats why i decided to make it dynamicly generated based on the selected stage ( Select )What does your data structure look like? Is this 33 separate fields on your table?
yes i have 33 defects in the defects table and 4 stages in the stages table
i have a junction table between them where most of the defects are applied on all of the stages
You might be able to generate the schema dynamically, I think the problem is that you are recreating the class property that your code is in, while the code is running.
i am generating it dynamically at the moment
the problem is that the
numberOfDefects
field ( that is part of the dynamic schema ) I want it to be able to make checks after the user has typed in something and color it before saving it in the DB
Witch means i need the afterStateUpdated
method. But that method is only triggered when i have the reactive()
method
Or if there is another way to trigger the afterStateUpdated()
method on the numberOfDefects
field without the reactive()
method ... that will also work but i don't know of such