->live on custom page Help
I have a custom page
However when the person changes the Template select drodown, nothing is triggering. Do I have to include anything in the template to get this to work?
<?php
namespace App\Filament\Resources\FcmNotificationTemplateResource\Pages;
use App\Filament\Resources\FcmNotificationTemplateResource;
use App\Models\FcmNotificationTemplate;
use App\Models\User;
use Filament\Forms\Components\MarkdownEditor;
use Filament\Forms\Components\Section;
use Filament\Forms\Components\Select;
use Filament\Forms\Components\TextInput;
use Filament\Forms\Concerns\InteractsWithForms;
use Filament\Forms\Contracts\HasForms;
use Filament\Forms\Form;
use Filament\Forms\Get;
use Filament\Resources\Pages\Page;
class SendTemplateToUser extends Page implements HasForms
{
use InteractsWithForms;
protected static string $resource = FcmNotificationTemplateResource::class;
protected static string $view = 'filament.resources.fcm-notification-template-resource.pages.send-template-to-user';
public function form(Form $form): Form
{
return $form
->schema([
Section::make('Template')
->schema([
Select::make('Template')
->options(FcmNotificationTemplate::all()->pluck('name', 'id'))
->live()
->afterStateUpdated(function (Select $component) {
dd('here');
return $component
->getContainer()
->getComponent('dynamicVariableFields')
->getChildComponentContainer()
->fill();
}),
Select::make('User')
->options(User::all()->pluck('name', 'id'))
->searchable()
]),
Section::make('Variables')
->schema(function (Get $get) {
$templateName = $get('Template');
if(!$templateName) return [];
$template = FcmNotificationTemplate::find($get('Template'));
dd($template);
return [
TextInput::make('title')
->default($template->title),
];
// return collect($template-)->map(function ($variable) {
// return TextInput::make($variable);
// });
})->key('dynamicVariableFields'),
TextInput::make('title')
->required(),
MarkdownEditor::make('content'),
// ...
])
->statePath('data');
}
}
<?php
namespace App\Filament\Resources\FcmNotificationTemplateResource\Pages;
use App\Filament\Resources\FcmNotificationTemplateResource;
use App\Models\FcmNotificationTemplate;
use App\Models\User;
use Filament\Forms\Components\MarkdownEditor;
use Filament\Forms\Components\Section;
use Filament\Forms\Components\Select;
use Filament\Forms\Components\TextInput;
use Filament\Forms\Concerns\InteractsWithForms;
use Filament\Forms\Contracts\HasForms;
use Filament\Forms\Form;
use Filament\Forms\Get;
use Filament\Resources\Pages\Page;
class SendTemplateToUser extends Page implements HasForms
{
use InteractsWithForms;
protected static string $resource = FcmNotificationTemplateResource::class;
protected static string $view = 'filament.resources.fcm-notification-template-resource.pages.send-template-to-user';
public function form(Form $form): Form
{
return $form
->schema([
Section::make('Template')
->schema([
Select::make('Template')
->options(FcmNotificationTemplate::all()->pluck('name', 'id'))
->live()
->afterStateUpdated(function (Select $component) {
dd('here');
return $component
->getContainer()
->getComponent('dynamicVariableFields')
->getChildComponentContainer()
->fill();
}),
Select::make('User')
->options(User::all()->pluck('name', 'id'))
->searchable()
]),
Section::make('Variables')
->schema(function (Get $get) {
$templateName = $get('Template');
if(!$templateName) return [];
$template = FcmNotificationTemplate::find($get('Template'));
dd($template);
return [
TextInput::make('title')
->default($template->title),
];
// return collect($template-)->map(function ($variable) {
// return TextInput::make($variable);
// });
})->key('dynamicVariableFields'),
TextInput::make('title')
->required(),
MarkdownEditor::make('content'),
// ...
])
->statePath('data');
}
}
3 Replies
Anyone have any idea?
you need the public prop
$data
check here
https://filamentphp.com/docs/3.x/forms/adding-a-form-to-a-livewire-component#adding-the-formthats exactly it thank you Lara!