->live on custom page Help

I have a custom page
<?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');
}
}
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?
3 Replies
datarecall
datarecall3mo ago
Anyone have any idea?
datarecall
datarecall3mo ago
thats exactly it thank you Lara!