F
Filament4mo ago
Trasek

Toggle button without database column?

Hey, can i add toggle button in form without column in database? Only as parametr to form to display or hide some elements?
2 Replies
ejoi8
ejoi84mo ago
Yes you can. You can try this
<?php

/**
* Toggle button to set show/hide respective field
*/
Toggle::make('show')->label(__('Show all details'))->inline()->live()
->afterStateUpdated(function (Set $set, $state) {
$set('service.show', !$state ? false : true);
}),



Tabs::make('Label')
->tabs([
Tabs\Tab::make('Service')
->icon('heroicon-m-user-circle')
->extraAttributes(['class' => 'inline-view'])
->schema([
Grid::make()
->relationship('service')
->schema([
DatePicker::make('info')
->label('Service Info')
->visible(fn(Get $get) => $get('show')) // field being show/hide base on the toggle button
])
->columns(1)
])
])
<?php

/**
* Toggle button to set show/hide respective field
*/
Toggle::make('show')->label(__('Show all details'))->inline()->live()
->afterStateUpdated(function (Set $set, $state) {
$set('service.show', !$state ? false : true);
}),



Tabs::make('Label')
->tabs([
Tabs\Tab::make('Service')
->icon('heroicon-m-user-circle')
->extraAttributes(['class' => 'inline-view'])
->schema([
Grid::make()
->relationship('service')
->schema([
DatePicker::make('info')
->label('Service Info')
->visible(fn(Get $get) => $get('show')) // field being show/hide base on the toggle button
])
->columns(1)
])
])
Want results from more Discord servers?
Add your server