final class PreviewItem extends Page
{
use InteractsWithRecord;
#[Url(keep: true)]
public int $stepIndex = 0;
public array $data = [];
protected static string $resource = ItemResource::class;
protected string $view = 'filament.resources.orders.resources.items.pages.preview-item';
public function mount(int | string $record): void
{
$this->record = $this->resolveRecord($record);
}
// This would be constructed from a json column containing a Filament Builder structure. Simplified for the sake of this example.
public function getStepSchemaComponents(): array
{
return [
[
TextInput::make('some_text_input')
->label('Text Input from Step 1'),
],
[
Textarea::make('some_textarea')
->label('Textarea From Step 2'),
],
][$this->stepIndex];
}
public function content(Schema $schema): Schema
{
return $schema
->reactive()
->statePath('data')
->components(fn () => $this->getStepSchemaComponents());
}
public function next(): void
{
// it properly retrieves the input data but somehow the schema is not changing across steps.
// if it's commented, going through the steps renders properly.
$data = $this->content->getState();
$this->stepIndex++;
}
public function previous(): void
{
$this->stepIndex--;
}
}
final class PreviewItem extends Page
{
use InteractsWithRecord;
#[Url(keep: true)]
public int $stepIndex = 0;
public array $data = [];
protected static string $resource = ItemResource::class;
protected string $view = 'filament.resources.orders.resources.items.pages.preview-item';
public function mount(int | string $record): void
{
$this->record = $this->resolveRecord($record);
}
// This would be constructed from a json column containing a Filament Builder structure. Simplified for the sake of this example.
public function getStepSchemaComponents(): array
{
return [
[
TextInput::make('some_text_input')
->label('Text Input from Step 1'),
],
[
Textarea::make('some_textarea')
->label('Textarea From Step 2'),
],
][$this->stepIndex];
}
public function content(Schema $schema): Schema
{
return $schema
->reactive()
->statePath('data')
->components(fn () => $this->getStepSchemaComponents());
}
public function next(): void
{
// it properly retrieves the input data but somehow the schema is not changing across steps.
// if it's commented, going through the steps renders properly.
$data = $this->content->getState();
$this->stepIndex++;
}
public function previous(): void
{
$this->stepIndex--;
}
}