Setting the default value of a TextInput within a Repeater
Hello, I'm trying to set the default value of TextInput within a Repeater using another field outside this repeater.
This is a simplified example of what I'm doing, unfortunately I'm not getting the value of cap field.
Any suggestions?
public static function form(Form $form): Form
{
return $form
->schema([
HiddenInput::make('cap'),
Repeater::make('numbers')
->schema([
TextInput::make('prefix')->default(fn (Get $get) => $get('../../cap')), // I will add a query that will use the value to retrieve data from DB
])
]);
}
Solution:Jump to solution
Do you want to do this?
```php
Forms\Components\Select::make('select')
->options([...
14 Replies
why not mutate before creating instead of hidden?
https://filamentphp.com/docs/3.x/panels/resources/creating-records#customizing-data-before-saving
I can do that, but what about the TextInput in the Repeater? What can I do to set is value?
using default, this is correct. Default only works in the create page
Yes, I'm using it in the create page. If I set a default value to the cap field I'm able to get it from prefix field. But what if cap field is set dynamically? Is there a way to set a repeater field value from outside the repeater?
But what if cap field is set dynamically?
How are you doing this?
I have a Select field, and in the "afterStateUpdated" I set the "cap" field depending on which option the user has selected in the Select field
afterStateUpdated you want to set all fields in the repeater with this value, right?
I was thinking of setting the repeater field based on the cap field, I mean within the repeater, using "Get". Anyway, setting the repeater field from the afterStateUpdated of the first Select field or the CAP TexInput would be ok.
we have more or less the same request , except that for me it is in a table
and that I want to copy the value of a specific ( let's say Column B) into column A if A is empty
so put the value of B as placeholder for example
I think the problem is related to ->default() method
This one does not work
TextInput::make('prefix')->default(fn (Get $get) => $get('../../cap'))
This one does work, I'm able to get cap from outside the repeater
Select::make('prefix')->options(function(Get $get){return ['cap' => $get('../../cap')];})
Solution
Do you want to do this?
I will try this way thank you
@Leandro Ferreira Thank you very much for your help! It works great using your code