Print array with Repeatableentry, how to?

I stored some data with a repeater in my form and I now want to output the data in a infolist with repeatableentry, but I can't get the data. The array looks like:
[{"data": {"other_income": [{"cost": "1000", "name": "Laundry", "period": "per-month"}, {"cost": "1000", "name": "Parking", "period": "per-month"}, {"cost": 0, "name": "Storage Rental", "period": "per-month"}]}, "type": "other_income"}]
[{"data": {"other_income": [{"cost": "1000", "name": "Laundry", "period": "per-month"}, {"cost": "1000", "name": "Parking", "period": "per-month"}, {"cost": 0, "name": "Storage Rental", "period": "per-month"}]}, "type": "other_income"}]
My Infolist
return $infolist
->record($this->record)
->schema([
RepeatableEntry::make('other_income')
->label('Other Income')
->schema([
TextEntry::make('cost'),
TextEntry::make('name'),
TextEntry::make('period'),
])
->columnSpanFull()
->columns(3)
->contained(false),
]);
return $infolist
->record($this->record)
->schema([
RepeatableEntry::make('other_income')
->label('Other Income')
->schema([
TextEntry::make('cost'),
TextEntry::make('name'),
TextEntry::make('period'),
])
->columnSpanFull()
->columns(3)
->contained(false),
]);
Would be glad if someone could help,please
No description
18 Replies
Dan Harrin
Dan Harrin2mo ago
is “data” a column on the record? or where is that from
TheNastyPasty
TheNastyPasty2mo ago
I don't know where that is from, is the default behaviour. Here my Code of the repeater
Builder\Block::make('other_income')
->schema([
Repeater::make('other_income')
->default([
['name' => 'Laundry'],
['name' => 'Parking'],
['name' => 'Storage Rental'],
])
->schema([
TextInput::make('name')
->live()
->string()
->maxLength(255)
->afterStateUpdated(function (Forms\Contracts\HasForms $livewire, Forms\Components\TextInput $component) {
$livewire->validateOnly($component->getStatePath());
}),
TextInput::make('cost')
->prefix('AED')
->live()
->numeric()
->default(0)
->minValue(0)
->maxValue(999999999)
->nullable()
->afterStateUpdated(function (Forms\Contracts\HasForms $livewire, Forms\Components\TextInput $component) {
$livewire->validateOnly($component->getStatePath());
}),
Select::make('period')
->live()
->selectablePlaceholder(false)
->enum(OtherIncomePeriod::class)
->options(OtherIncomePeriod::class)
->default(OtherIncomePeriod::PerMonth->value),
])->columnSpan(2)->maxItems(20)->itemLabel(fn (array $state): ?string => $state['name'] ?? null),
]),
])->columnSpan(2)->addable()->maxItems(1)
->collapseAllAction(
fn (Action $action) => $action->label('Collapse all content'),
),
Builder\Block::make('other_income')
->schema([
Repeater::make('other_income')
->default([
['name' => 'Laundry'],
['name' => 'Parking'],
['name' => 'Storage Rental'],
])
->schema([
TextInput::make('name')
->live()
->string()
->maxLength(255)
->afterStateUpdated(function (Forms\Contracts\HasForms $livewire, Forms\Components\TextInput $component) {
$livewire->validateOnly($component->getStatePath());
}),
TextInput::make('cost')
->prefix('AED')
->live()
->numeric()
->default(0)
->minValue(0)
->maxValue(999999999)
->nullable()
->afterStateUpdated(function (Forms\Contracts\HasForms $livewire, Forms\Components\TextInput $component) {
$livewire->validateOnly($component->getStatePath());
}),
Select::make('period')
->live()
->selectablePlaceholder(false)
->enum(OtherIncomePeriod::class)
->options(OtherIncomePeriod::class)
->default(OtherIncomePeriod::PerMonth->value),
])->columnSpan(2)->maxItems(20)->itemLabel(fn (array $state): ?string => $state['name'] ?? null),
]),
])->columnSpan(2)->addable()->maxItems(1)
->collapseAllAction(
fn (Action $action) => $action->label('Collapse all content'),
),
Dan Harrin
Dan Harrin2mo ago
can you open an issue with a reproduction repo please start from scratch and only add the minimal amount of code required to reproduce, and a seeder
TheNastyPasty
TheNastyPasty2mo ago
Will try it, have never done this before "data is added because of the Block Builder, tested it
Dan Harrin
Dan Harrin2mo ago
i think this would work better with a repeater instead of a builder? because the infolist doesnt know there are multiple block types either
TheNastyPasty
TheNastyPasty2mo ago
What do you mean I should remove the Blocks from the form and only work with repeaters?
Dan Harrin
Dan Harrin2mo ago
why did you choose the builder?
TheNastyPasty
TheNastyPasty2mo ago
Because the Form is more structured and organized
Dan Harrin
Dan Harrin2mo ago
hmm, not sure i understand you only have one block type?
TheNastyPasty
TheNastyPasty2mo ago
different blocks with different headings
Dan Harrin
Dan Harrin2mo ago
so how are you rendering those with a repeatableentry when there is only one schema
TheNastyPasty
TheNastyPasty2mo ago
Ok I dont understand, so it would be better for me to remove the block and only use the repeater and then the repeatableentry should work as expected?
Dan Harrin
Dan Harrin2mo ago
your problem right now is that filament doesnt know you have a data array so you need to add data. to the field name, or move to a more simple json structure
TheNastyPasty
TheNastyPasty2mo ago
Yeah sure but how to do that in a infolist/repeatableentry?
Dan Harrin
Dan Harrin2mo ago
well if you get rid of the builder so theres just a repeater, you can keep the same code
TheNastyPasty
TheNastyPasty2mo ago
and otherwise? is there something like "other_income.data"?
Dan Harrin
Dan Harrin2mo ago
would actually be data.other_income but you still need to overcome the first layer of repetition you currently have a builder and repeater, so thats 2 nested arrays but you only have one repeatableentry so you'd at least need to wrap the repeatableentry in another repeatableentry called "other_income" and the nested one would be data.other_income which would then make the nested fields other_income.0.data.other_income.0.name etc, which is the correct path
TheNastyPasty
TheNastyPasty2mo ago
Wow thanks for the explaination