Valcro
Valcro
FFilament
Created by Valcro on 9/12/2024 in #❓┊help
Inserting livewire component into a form, how to manage state?
Hello, following this section of the documentation: https://filamentphp.com/docs/3.x/forms/advanced#inserting-livewire-components-into-a-form I have a wizard form with 3 steps to create a record of a resource.
public function getSteps(): array
{
return [
Step::make('Step A')
->schema([
TextInput::make('stepa')
]),
Step::make('Step B')
->schema([
TextInput::make('stepb')
]),
Step::make('Step C')
->schema([
Livewire::make(AppointmentSlotField::class)
]),
];
}
public function getSteps(): array
{
return [
Step::make('Step A')
->schema([
TextInput::make('stepa')
]),
Step::make('Step B')
->schema([
TextInput::make('stepb')
]),
Step::make('Step C')
->schema([
Livewire::make(AppointmentSlotField::class)
]),
];
}
The first two steps uses filament TextInput fields, the third step uses a livewire component. When creating the record, the first two fields are automatically synced in the form state so when I create the record and inspect the data:
protected function mutateFormDataBeforeCreate(array $data): array
{
dd($data);
}
protected function mutateFormDataBeforeCreate(array $data): array
{
dd($data);
}
I have the values of the TextInput fields correctly:
array:2 [// app\Filament\Resources\AppointmentResource\Pages\CreateAppointment.php:24
"stepa" => "1"
"stepb" => "1"
]
array:2 [// app\Filament\Resources\AppointmentResource\Pages\CreateAppointment.php:24
"stepa" => "1"
"stepb" => "1"
]
My question is: How can I access the state of the form fields within the livewire component Livewire::make(AppointmentSlotField::class) and set new values to the form? So when creating the record, I expect to have this output:
array:3 [// app\Filament\Resources\AppointmentResource\Pages\CreateAppointment.php:24
"stepa" => "1"
"stepb" => "1"
"stepc" => "1"
]
array:3 [// app\Filament\Resources\AppointmentResource\Pages\CreateAppointment.php:24
"stepa" => "1"
"stepb" => "1"
"stepc" => "1"
]
This is the livewire component:
<?php

namespace App\Livewire;

use Illuminate\Contracts\View\View;
use Livewire\Component;

class AppointmentSlotField extends Component
{
public function render(): View
{
return view('livewire.appointment-slot-field');
}
}
<?php

namespace App\Livewire;

use Illuminate\Contracts\View\View;
use Livewire\Component;

class AppointmentSlotField extends Component
{
public function render(): View
{
return view('livewire.appointment-slot-field');
}
}
9 replies
FFilament
Created by Valcro on 2/16/2024 in #❓┊help
Select Column relationship in Table.
I'm currently populating the select using the options closure:
Tables\Columns\SelectColumn::make('currency_id')
->label('Currency')
->options(fn (Currency $currency) => $currency->pluck('name', 'id'))
Tables\Columns\SelectColumn::make('currency_id')
->label('Currency')
->options(fn (Currency $currency) => $currency->pluck('name', 'id'))
But do we have a way to access a relationship like as in the Form Builder?:
Forms\Components\Select::make('currency_id')
->relationship(name: 'currency', titleAttribute: 'name')
Forms\Components\Select::make('currency_id')
->relationship(name: 'currency', titleAttribute: 'name')
Is there a better way to do this?
4 replies