FilamentF
Filament5mo ago
hootch

Fill form in CreateAction

i have Offices and Members,
if a member is created from an already existing office office_id should be forced (pre-filled)
i created a MembersRelationManager that extends RelationManager, i have MembersTable with headerActions:
CreateAction::make()
    ->label('Create New Member')
    ->successNotificationTitle('Member created successfully')
    ->mutateDataUsing(function (array $data): array {
        $data['office_id'] = $this->getOwnerRecord()->id;
        return $data;
    }),

mutateDataUsing is setting the office_id after creating and before inserting to DB,
but what i want is to fill the form with office_id initially,
is there any way to pre-fill the form, or set data somewhere so it can reflect into the form?

PS: EditAction in the other hand has mutateRecordDataUsing which does the job
EditAction::make()
    ->slideOver()
    ->successNotificationTitle('Member updated successfully')
    ->mutateRecordDataUsing(function (array $data): array {
        $data['office_id'] = $this->getOwnerRecord()->id;

        return $data;
    }),
Solution
You use use the ->fillForm() method on the CreateAction
Was this page helpful?