F
Filament7mo ago
Fasna

Repeater and auto-increment field

I have a form with a repeater and I have a field for the number of the element. I want that field to be prefilled and created whenever clicking the 'Add' button. I got the maximum number from DB and prefilled the field(the label), but it won't apply to the next element until I save the last one.
return Repeater::make('engine_llps')->label('Engine LLPs')
->relationship()
->columns(13)
->itemLabel(fn(array $state): ?string => 'LLP Number ' . $state['llp_number'] ?? null)
->schema([
Forms\Components\TextInput::make('llp_number')
->label('LLP Number')->hidden()->default(fn(Get $get) => CRMEngineLLPInformation::where('crm_engine_id', $get('../../engine_id'))->max('llp_number') + 1),
])
return Repeater::make('engine_llps')->label('Engine LLPs')
->relationship()
->columns(13)
->itemLabel(fn(array $state): ?string => 'LLP Number ' . $state['llp_number'] ?? null)
->schema([
Forms\Components\TextInput::make('llp_number')
->label('LLP Number')->hidden()->default(fn(Get $get) => CRMEngineLLPInformation::where('crm_engine_id', $get('../../engine_id'))->max('llp_number') + 1),
])
No description
0 Replies
No replies yetBe the first to reply to this messageJoin
Want results from more Discord servers?
Add your server