Repeater: TextInput action always returning last record in Model $record

I have an action in a repeater that need access to the current repeater entry:
Repeater::make('test')
->schema([
Hidden::make('id'),
TextInput::make('value')
->hintAction(
Action::make('display_value')
->schema([
TextInput::make('new_amount')
->required()
->numeric()
->minValue(0),
])
->action(function (Get $get) {
ray($get('id'), $get('value'));
}),
),
]),
Repeater::make('test')
->schema([
Hidden::make('id'),
TextInput::make('value')
->hintAction(
Action::make('display_value')
->schema([
TextInput::make('new_amount')
->required()
->numeric()
->minValue(0),
])
->action(function (Get $get) {
ray($get('id'), $get('value'));
}),
),
]),
In my form I also add the following to put very basic test data in into the form:
protected function fillForm(): void
{
parent::fillForm();

$this->form->fill([
'test' => [
[
'id' => 1,
'value' => 100,
],
[
'id' => 2,
'value' => 200,
]
]
]);
}
protected function fillForm(): void
{
parent::fillForm();

$this->form->fill([
'test' => [
[
'id' => 1,
'value' => 100,
],
[
'id' => 2,
'value' => 200,
]
]
]);
}
Trying $get('id') returns the value of the last row 2 when it should be 1. Similar thing happens when I try to use ->relationship and get the current Model $record. Any ideas?
No description
Solution:
```php ->hintAction(fn (Get $get): Action => Action::make('display_value') ->schema([ TextInput::make('new_amount'), ])...
Jump to solution
3 Replies
Solution
LeandroFerreira
->hintAction(fn (Get $get): Action => Action::make('display_value')
->schema([
TextInput::make('new_amount'),
])
->action(function (array $data) use ($get) {
ray($get('id'), $get('value'), $data);
}),
)
->hintAction(fn (Get $get): Action => Action::make('display_value')
->schema([
TextInput::make('new_amount'),
])
->action(function (array $data) use ($get) {
ray($get('id'), $get('value'), $data);
}),
)
Harvey
HarveyOP4w ago
Thanks that was it 👍
LeandroFerreira
and inject array $data to get the new_amount ☝️

Did you find this page helpful?