F
Filamentβ€’10mo ago
d3v1anX

Widget Live form

Hey Guys, tried to add a form in a widget (with HasForms / InteractsWithForms) but unfortunately there is no live update on change. Is it not possible to do a live Form-Field?
<?php

namespace App\Filament\User\Widgets;

use Filament\Forms\Components\TextInput;
use Filament\Forms\Concerns\InteractsWithForms;
use Filament\Forms\Contracts\HasForms;
use Filament\Forms\Form;
use Filament\Widgets\Widget;

class Testwidget extends Widget implements HasForms
{
use InteractsWithForms;

protected static string $view = 'filament.user.widgets.testwidget';

public function form(Form $form)
{
return $form->
schema([
TextInput::make('test')
->live()
->afterStateUpdated(fn () => dd('test')),
]);
}
}
<?php

namespace App\Filament\User\Widgets;

use Filament\Forms\Components\TextInput;
use Filament\Forms\Concerns\InteractsWithForms;
use Filament\Forms\Contracts\HasForms;
use Filament\Forms\Form;
use Filament\Widgets\Widget;

class Testwidget extends Widget implements HasForms
{
use InteractsWithForms;

protected static string $view = 'filament.user.widgets.testwidget';

public function form(Form $form)
{
return $form->
schema([
TextInput::make('test')
->live()
->afterStateUpdated(fn () => dd('test')),
]);
}
}
B lade File:
<x-filament-widgets::widget>
<x-filament::section>
{{ $this->form }}
</x-filament::section>
</x-filament-widgets::widget>
<x-filament-widgets::widget>
<x-filament::section>
{{ $this->form }}
</x-filament::section>
</x-filament-widgets::widget>
Solution:
Oh my god - did the same mistake as in https://discord.com/channels/883083792112300104/1161190672708153465 The test variable must be set as public - only then the "afterStateUpdated" function will be called....
Jump to solution
2 Replies
Solution
d3v1anX
d3v1anXβ€’10mo ago
Oh my god - did the same mistake as in https://discord.com/channels/883083792112300104/1161190672708153465 The test variable must be set as public - only then the "afterStateUpdated" function will be called.
toeknee
toekneeβ€’10mo ago
That's Livewire 101 πŸ˜‰ you can pass a state for the form though so you only need to define on array variable and fetch data from that