F
Filamentβ€’12mo ago
Robin

Repeater

In a many to many rlsp, how can I access fields inside the reapeater?
9 Replies
Robin
RobinOPβ€’12mo ago
that is, using $set/$get outise repeater to access fields inside the repeater
Anik
Anikβ€’12mo ago
I have a similar use case. I need to access previous row values inside repeater for validation. Kindly let me know if you find a solution πŸ™‚
Robin
RobinOPβ€’12mo ago
If that's your case, there's an answer already in the docs, a sec I'll send you the link
Robin
RobinOPβ€’12mo ago
what I'm tryna do is now acces the values (inside the repeater), outside the repeater Unless you trying to do the same thing πŸ˜ƒ
Anik
Anikβ€’12mo ago
I have tried but in my use case I am trying to access item1 values of the repeater from item2. Maybe we can do it if we add specific keys to the repeater array and get data from the keys
Robin
RobinOPβ€’12mo ago
Item1 and item 2 are they both inside the repeater?
ziolupo
ziolupoβ€’12mo ago
Maybe this can help. I have a repeater, when I toggle to true one item, all the toggle button of the other must be set to false. This is my code used inside the repeater:
Repeater::make('exhibitionWines')
->hiddenLabel()
->relationship()
->schema([
Forms\Components\Select::make('wine_id')
->relationship('wine', 'name')
->native(false)
->required()
->preload()
->columnSpan(3),
Forms\Components\Toggle::make('in_masterclass')
->reactive()
->live()
->afterStateUpdated(function($state,Set $set, Get $get)
{
$items=$get('../../exhibitionWines'); // The name of the repeater
$current_id=$get('wine_id');
if($state==true){
foreach ($items as $key => $item) {
if ($item['wine_id']!=$current_id){
$set("../../exhibitionWines.{$key}.in_masterclass",false); //The "other" items
}
}
}
})
Repeater::make('exhibitionWines')
->hiddenLabel()
->relationship()
->schema([
Forms\Components\Select::make('wine_id')
->relationship('wine', 'name')
->native(false)
->required()
->preload()
->columnSpan(3),
Forms\Components\Toggle::make('in_masterclass')
->reactive()
->live()
->afterStateUpdated(function($state,Set $set, Get $get)
{
$items=$get('../../exhibitionWines'); // The name of the repeater
$current_id=$get('wine_id');
if($state==true){
foreach ($items as $key => $item) {
if ($item['wine_id']!=$current_id){
$set("../../exhibitionWines.{$key}.in_masterclass",false); //The "other" items
}
}
}
})
Want results from more Discord servers?
Add your server