[Reapeater] Repeater question about one column getting data from the other one

Hi guys, I have a "users" table, which has id, title and age columns among others. I'd like to build a repeater made from 2 columns. The first column would be a general select, made up of user id's and titles. The second column, I'd like to be a text input and get filled with users age upon the selection of a user in the first column. I'm having trouble coming up on how to do this and, is it even possible? Any help would be appreciated, thanks!
Solution:
You can use afterStateUpdated() and $set to set the value of another field. Assuming the select field contains the ID value of the user and the age field is called 'age' on the repeater: ```php...
Jump to solution
2 Replies
Solution
crankier
crankier10mo ago
You can use afterStateUpdated() and $set to set the value of another field. Assuming the select field contains the ID value of the user and the age field is called 'age' on the repeater:
Select::make('user_id')
->afterStateUpdated(function($state, Set $set){
$user = User::find($state);
$set('age',$user->age)
})
Select::make('user_id')
->afterStateUpdated(function($state, Set $set){
$user = User::find($state);
$set('age',$user->age)
})
You can read up more about form injection here https://filamentphp.com/docs/3.x/forms/advanced#form-component-utility-injection
Gediminas
GediminasOP10mo ago
Thanks man, this works great!
Want results from more Discord servers?
Add your server