Is it possible to force refresh Form programitically?

I have a Section which the schema of it dynamically generated when the state of a "Select" component changes.
// Select Component
Select::make('form_type_id')
->label('Form Türü')
->options(function ($livewire) {
$arr = [];
foreach ($livewire->getParentRecord()->forms as $form) {
$arr[$form->id] = $form->name;
}
return $arr;
})
->preload()
->live()
->required()
->native(false)
->columnSpan([
'lg' => 3,
'default' => 'full',
]),

// Dynamically set Section
Section::make()
->id('form_answers_section')
->schema(function (Get $get) use ($schema) {
$formType = $get('form_type_id');
if (blank($formType)) {
return [];
}
$formSchema = GroupFormTypes::find($formType)->form->schema;
return FormBuilder::make($formSchema)
->fileUploaderModel($schema->getRecord())->adminPreview()->build();
})
->columns([
'default' => 10
])
->columnSpanFull()
->id('form_answers')
->key('form_answers') // https://github.com/filamentphp/filament/issues/18008
->statePath('form_answers')
// Select Component
Select::make('form_type_id')
->label('Form Türü')
->options(function ($livewire) {
$arr = [];
foreach ($livewire->getParentRecord()->forms as $form) {
$arr[$form->id] = $form->name;
}
return $arr;
})
->preload()
->live()
->required()
->native(false)
->columnSpan([
'lg' => 3,
'default' => 'full',
]),

// Dynamically set Section
Section::make()
->id('form_answers_section')
->schema(function (Get $get) use ($schema) {
$formType = $get('form_type_id');
if (blank($formType)) {
return [];
}
$formSchema = GroupFormTypes::find($formType)->form->schema;
return FormBuilder::make($formSchema)
->fileUploaderModel($schema->getRecord())->adminPreview()->build();
})
->columns([
'default' => 10
])
->columnSpanFull()
->id('form_answers')
->key('form_answers') // https://github.com/filamentphp/filament/issues/18008
->statePath('form_answers')
The problem is that when I select a value from this "Select" component named form_type_id , I get Livewire Entangle Error and the form itself loses it's reactivity until a livewire/update endpoint called and the form has been refreshed. I am looking for a way to solve this problem.
No description
5 Replies
toeknee
toeknee5w ago
Yes, see; https://github.com/filamentphp/filament/discussions/1648 But I think your problem isn't refreshing the data it is actually mounting the structure. The structure doesn't exist on mount which needs too, otherwise people could add random fields and hope they save. It's a security aspect of Livewire. Instead, mount all possible fields and control the visibility.
GitHub
Reload edit or view page after an Action · filamentphp filament ·...
Hello, Sorry if is a noob question, I have a Modal action and I would like to refresh my Edit page after I complied that action. For sure is really easy and I will look really bad.. hahaha Thanks i...
Zamion101
Zamion101OP5w ago
Doesn't mounting all the fields/forms takes a time with each form/fields and also with every livewire/update all the fields must refresh (even if it's partially rendered)? So the overhead is a bit too much to mount all the fields. Also the link does not solve my problem unfortunately.
toeknee
toeknee5w ago
Yes and no, there won’t be any HTML if the fields are not visible so it’s not as heavy. But that’s the downside to livewire is that on mount you need the fields needed to be mounted that can or could be visible
Zamion101
Zamion101OP5w ago
So even if I were to "refresh" the form, the "Entagle" problem may not be solved because Livewire expects the element to present when mounting anything that depends on it. Hmm so like you mentioned, maybe I should mount all the fields but use ->visible to selectively not include in the html is this correct? What happens to the validation though? I tried your suggested way. I have mounted all the forms as sections but the livewire/update takes but 850+ms to update the form and I can feel the stuttering when clicking ToggleButtons, Selects and etc. As a bandaid this is not a bad approach but if there is another possible way, I will be really happy to know. Thank you.
toeknee
toeknee5w ago
I can't see how else to do it. The fields which can be added conditionally would need to be mounted. This is a way of doing it slightly different but similar, not tried it myself. https://stackoverflow.com/questions/73692912/how-to-dynamically-add-input-fields-with-livewire
Stack Overflow
How to dynamically add input fields with livewire
I want add new Inputbox to be created when the user clicks the add button. I tried the following code but it didn't work, And I get the following error: get_class(): Argument #1 ($object) must be of

Did you find this page helpful?