F
Filament15mo ago
Crylar

Is it possible to hide some form elements when calling via view action?

I would like to somehow detect that form was loaded by using view action and modity the form layout slightly.
4 Replies
Dan Harrin
Dan Harrin15mo ago
->hiddenOn('view')
Crylar
Crylar15mo ago
Hm, I have tried it before writing but it did not work for some reason. I have this view action
Tables\Actions\ViewAction::make('products'),
Tables\Actions\ViewAction::make('products'),
and this is how my form looks like
public static function form(Form $form): Form
{
return $form
->schema([
Forms\Components\Card::make([
Forms\Components\Grid::make()->schema([
Forms\Components\TextInput::make('number')
->dehydrated(false)
->disabled(),

Forms\Components\TextInput::make('location')
->formatStateUsing(fn (Order $record) => $record->location ?: 'n/a')
->dehydrated(false)
->disabled(),
]),

Forms\Components\Select::make('status')
->options(array_map(fn ($item) => Str::title($item), Arr::except(OrderStatus::toArray(), ['cart'])))
->required(),
])
->hiddenOn('view'),

...................

]);
}
public static function form(Form $form): Form
{
return $form
->schema([
Forms\Components\Card::make([
Forms\Components\Grid::make()->schema([
Forms\Components\TextInput::make('number')
->dehydrated(false)
->disabled(),

Forms\Components\TextInput::make('location')
->formatStateUsing(fn (Order $record) => $record->location ?: 'n/a')
->dehydrated(false)
->disabled(),
]),

Forms\Components\Select::make('status')
->options(array_map(fn ($item) => Str::title($item), Arr::except(OrderStatus::toArray(), ['cart'])))
->required(),
])
->hiddenOn('view'),

...................

]);
}
I am trying to hide Card component on view action.
Dan Harrin
Dan Harrin15mo ago
just use Tables\Actions\ViewAction::make(),
Crylar
Crylar15mo ago
Oh right, this changes the name of the view action. So technically I could have hiddenOn('products') and it works. 🙂 Nice, thanks.
Want results from more Discord servers?
Add your server
More Posts