F
Filament3y ago
mcdc

Repeater: Get current form id

I have this task table where fields are id, title, description, creator_id, due_date, parent_id, type I added Repeater on my $form , my goal is I want create sub task, which is determine by type and also under what main task parent_id. How to get the id and assign it as default on my TextInput::make('parent_id')
return $form
->schema([
TextInput::make('title')
->required()
->autofocus(),
Forms\Components\MultiSelect::make('user_id')
->label('Assigned to')
->relationship('assignees','user_id')
->multiple()
->options(User::pluck('name','id')->toArray()),
DatePicker::make('due_date')
->label('Due Date')
->minDate(now()),
TextInput::make('creator_name')
->label('Created by')
->default(auth()->user()->name)
->disabled()
->hint('Creator: '.auth()->user()->name)
->hintIcon('tabler-info-circle'),
TextInput::make('creator_id')
->default(auth()->user()->id)
->hidden(),
Textarea::make('description')->required(),
Forms\Components\Repeater::make('subtask')
->schema([
TextInput::make('title')->required(),
Textarea::make('description')->required(),
TextInput::make('parent_id')
->default() // this id of the task
->hidden(),
])
->createItemButtonLabel('Add subtask')
->collapsed()
]);
return $form
->schema([
TextInput::make('title')
->required()
->autofocus(),
Forms\Components\MultiSelect::make('user_id')
->label('Assigned to')
->relationship('assignees','user_id')
->multiple()
->options(User::pluck('name','id')->toArray()),
DatePicker::make('due_date')
->label('Due Date')
->minDate(now()),
TextInput::make('creator_name')
->label('Created by')
->default(auth()->user()->name)
->disabled()
->hint('Creator: '.auth()->user()->name)
->hintIcon('tabler-info-circle'),
TextInput::make('creator_id')
->default(auth()->user()->id)
->hidden(),
Textarea::make('description')->required(),
Forms\Components\Repeater::make('subtask')
->schema([
TextInput::make('title')->required(),
Textarea::make('description')->required(),
TextInput::make('parent_id')
->default() // this id of the task
->hidden(),
])
->createItemButtonLabel('Add subtask')
->collapsed()
]);
1 Reply
Dan Harrin
Dan Harrin3y ago
you dont need the ID field you just need to define a ->relationship() on the repeater and we handle saving it check the repeater docs

Did you find this page helpful?