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 Harrin2y ago
->hiddenOn('view')
Crylar
CrylarOP2y 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 Harrin2y ago
just use Tables\Actions\ViewAction::make(),
Crylar
CrylarOP2y ago
Oh right, this changes the name of the view action. So technically I could have hiddenOn('products') and it works. 🙂 Nice, thanks.

Did you find this page helpful?