F
Filamentβ€’2y ago
Crylar

How can I get Resource Form inside the action ->form ?

I have the following code:
Tables\Actions\ReplicateAction::make('replicate')
->iconButton()
->excludeAttributes(['category_title'])
->form(function () {

})
Tables\Actions\ReplicateAction::make('replicate')
->iconButton()
->excludeAttributes(['category_title'])
->form(function () {

})
I was wondering how would I get data from
public static function form(Form $form): Form
{
return $form
public static function form(Form $form): Form
{
return $form
I could do
static::form(...)
static::form(...)
but not sure what to input as a Form variable here. Please advice what's the best approach in reusing form schema. Thanks.
6 Replies
Dennis Koch
Dennis Kochβ€’2y ago
I think it's YourResource::form(new Form)->getFormSchema() You could also just put it inside a static method that gets called from both
Crylar
CrylarOPβ€’2y ago
You mean something like this?
protected static function getGenericForm(): array
{
return [
Forms\Components\TextInput::make('title')
->required()
];
}
protected static function getGenericForm(): array
{
return [
Forms\Components\TextInput::make('title')
->required()
];
}
return $form
->schema([
Forms\Components\Card::make([
...static::getGenericForm()
])
return $form
->schema([
Forms\Components\Card::make([
...static::getGenericForm()
])
Tables\Actions\ReplicateAction::make('replicate')
->iconButton()
->excludeAttributes(['category_title'])
->form([
...static::getGenericForm()
])
Tables\Actions\ReplicateAction::make('replicate')
->iconButton()
->excludeAttributes(['category_title'])
->form([
...static::getGenericForm()
])
Dennis Koch
Dennis Kochβ€’2y ago
Yes.
Crylar
CrylarOPβ€’2y ago
Cool πŸ™‚
Dennis Koch
Dennis Kochβ€’2y ago
If you don’t want a separate method, try version 1 πŸ˜…
Crylar
CrylarOPβ€’2y ago
Yeh, but I guess I would not need as many hiddenOn rules if I separate πŸ˜„ This can get complex to manage very fast. πŸ™‚
Want results from more Discord servers?
Add your server