F
Filament6mo ago
Azade

How to use the value of a field in a form in another modal in filament.

How to use the value of a field in a form in another modal in filament. (The modal that I mentioned is in form) For example in this code I'm gonna set price1. but the value of $get('price') is null in the modal!
->schema([
TextInput::make('price'),
Forms\Components\Actions::make([
Action::make('Custom Modal')
->button()
->form([
TextInput::make('price1')->prefix('$')->required()
->default(
function (Set $set, Get $get) {
$set('price1', $get('price'));
return $get('price');
}
),
])
->action(function (Set $set, Get $get, array $data) {
$set('price', $data['price1']);
}),
]),
->schema([
TextInput::make('price'),
Forms\Components\Actions::make([
Action::make('Custom Modal')
->button()
->form([
TextInput::make('price1')->prefix('$')->required()
->default(
function (Set $set, Get $get) {
$set('price1', $get('price'));
return $get('price');
}
),
])
->action(function (Set $set, Get $get, array $data) {
$set('price', $data['price1']);
}),
]),
Solution:
After testing a lot of ways, Now this is the answer: ```php .... Wizard\Step::make('First Step') ->schema([...
Jump to solution
1 Reply
Solution
Azade
Azade6mo ago
After testing a lot of ways, Now this is the answer:
....
Wizard\Step::make('First Step')
->schema([
TextInput::make('title')->required(),
Hidden::make('price'),
Forms\Components\Actions::make([
Action::make('Custom Modal')
->button()
->form([
TextInput::make('price')->prefix('$')->required()
->default(
function (MyModel $record = null) {
return $record?->price;
}
),
])
->action(function (Set $set, array $data) {
$set('price', $data['price']);
}),
]),

]),
....
....
Wizard\Step::make('First Step')
->schema([
TextInput::make('title')->required(),
Hidden::make('price'),
Forms\Components\Actions::make([
Action::make('Custom Modal')
->button()
->form([
TextInput::make('price')->prefix('$')->required()
->default(
function (MyModel $record = null) {
return $record?->price;
}
),
])
->action(function (Set $set, array $data) {
$set('price', $data['price']);
}),
]),

]),
....