F
Filament7mo 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
Tally7mo 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
nowakOP7mo ago
Thanks! Didn't know about the extraFieldWrapperAttributes
Tally
Tally7mo ago
one of the many hidden gems 😉
Want results from more Discord servers?
Add your server