F
Filament2mo ago
nowak

Hide TextInput form field but keep spacing it's spacing

Hi, I am looking for a way to conditionally hide a TextInput field, without messing up the height of the schema, is this possible? This is my TextInput field:
TextInput::make('other_reason_text')
->hidden(fn (Get $get) => $get('reason') !== 'Other')
->nullable()
->maxLength(255),
TextInput::make('other_reason_text')
->hidden(fn (Get $get) => $get('reason') !== 'Other')
->nullable()
->maxLength(255),
Which is used in a Repeater item schema like this:
Repeater::make('complaintDetails')
->label('Order Items')
->relationship('complaintDetails')
->schema([
Select::make('reason')
->options([
'Missing from delivery' => 'Missing from delivery',
'Damaged product' => 'Damaged product',
'Wrong item' => 'Wrong item',
'Other' => 'Other',
])
->required()
->placeholder('Select a Reason')
->disableOptionsWhenSelectedInSiblingRepeaterItems()
->native(false),
TextInput::make('other_reason_text')
->hidden(fn (Get $get) => $get('reason') !== 'Other')
->nullable()
->maxLength(255),
Select::make('user_order_item_ids')
->multiple()
->relationship('userOrderItems', 'product_name', function (Builder $query, Get $get) {
$userOrderId = $get('../../user_order_id');
if ($userOrderId) {
$query->where('user_order_id', $userOrderId);
} else {
$query->whereRaw('1 = 0');
}
})
->placeholder('Select an Order Item')
->searchable()
->preload(),
])
->grid(3)
->columnSpanFull(),
Repeater::make('complaintDetails')
->label('Order Items')
->relationship('complaintDetails')
->schema([
Select::make('reason')
->options([
'Missing from delivery' => 'Missing from delivery',
'Damaged product' => 'Damaged product',
'Wrong item' => 'Wrong item',
'Other' => 'Other',
])
->required()
->placeholder('Select a Reason')
->disableOptionsWhenSelectedInSiblingRepeaterItems()
->native(false),
TextInput::make('other_reason_text')
->hidden(fn (Get $get) => $get('reason') !== 'Other')
->nullable()
->maxLength(255),
Select::make('user_order_item_ids')
->multiple()
->relationship('userOrderItems', 'product_name', function (Builder $query, Get $get) {
$userOrderId = $get('../../user_order_id');
if ($userOrderId) {
$query->where('user_order_id', $userOrderId);
} else {
$query->whereRaw('1 = 0');
}
})
->placeholder('Select an Order Item')
->searchable()
->preload(),
])
->grid(3)
->columnSpanFull(),
Solution:
Nice question 😉 you mean invisible? Maybe try this ```PHP Forms\Components\TextInput::make('other_reason_text') ->extraFieldWrapperAttributes(function (Forms\Get $get){...
Jump to solution
3 Replies
Solution
Tally
Tally2mo ago
Nice question 😉 you mean invisible? Maybe try this
Forms\Components\TextInput::make('other_reason_text')
->extraFieldWrapperAttributes(function (Forms\Get $get){
if ($get('reason') !== 'Other') {
return ['class' => 'invisible'];
}
return [];
})
->nullable()
->maxLength(255),
Forms\Components\TextInput::make('other_reason_text')
->extraFieldWrapperAttributes(function (Forms\Get $get){
if ($get('reason') !== 'Other') {
return ['class' => 'invisible'];
}
return [];
})
->nullable()
->maxLength(255),
nowak
nowak2mo ago
Thanks! Didn't know about the extraFieldWrapperAttributes
Tally
Tally2mo ago
one of the many hidden gems 😉
Want results from more Discord servers?
Add your server
More Posts
Fill form data from from ControllerI have this custom field that behaves just like a normal TextInput, but i've place a button near it Hide create button in a form with wizardHi everyone! I'm using a Wizard in a form when creating a resource. My submit button is at the lastSpecifying navigation items order within navigation groupsHow do I specify the navigation items order withing navigation groups? I can order the navigation gUncaught Snapshot missing on Livewire component with id: QAcNIGM0wsdXZxTaZYW7Hello, I have a widget on the dashboard panel and I run into this error: ```livewire.js?id=07f2287Livewire Component Not WorkingHello, I add a livewire component consisting on a select of options. When the select changes, nothinFileupload on registration page - 419 errorFor full context, we have a Filament app with 2 panels - Admin & Member. When a member registers, anCan't login into panel when user model use uuidHello i'm using uuid's on mi user model, I have configured all what is necessary to use it but I caAuthorize Imports: Apply different policy methods on create and updateI am using `authorize` method for Importer to show it only to the users that have `create` authorizaReplicate action: load form instead of saveI was searching for a way to add ***Clone*** table action, and came across ***Replicate*** action. TFilament Shield allows create/edit/delete despite role restrictions. Shouldn't have these permissionThe Filament plugin shield still allows users to create, edit, and delete even though I have not giv