How to add a button inside a section in form?

I want to add unset button to to photo and video Example
Forms\Components\Section::make('Photo')
->schema([
Placeholder::make('photo')
->content(fn ($record) => self::getImageContent($record) )
->visibleOn('edit')
->hidden(fn (?Advertisement $record, Forms\Get $get) =>
($record === null) || (!!$get('new_photo'))
),
Forms\Components\FileUpload::make('new_photo')
->image()
->storeFiles(false)
->moveFiles()
->imageEditor(),
Forms\Components\Button::make('unset_video')
->label('Unset Video')
->color('danger')
->action(fn () => $this->unsetVideo()),
])
->columns(2)
->collapsible()
->collapsed(),

public $unsetPhoto = false;
public $unsetVideo = false;

public function unsetPhoto()
{
$this->unsetPhoto = true;
}

public function unsetVideo()
{
$this->unsetVideo = true;
}
Forms\Components\Section::make('Photo')
->schema([
Placeholder::make('photo')
->content(fn ($record) => self::getImageContent($record) )
->visibleOn('edit')
->hidden(fn (?Advertisement $record, Forms\Get $get) =>
($record === null) || (!!$get('new_photo'))
),
Forms\Components\FileUpload::make('new_photo')
->image()
->storeFiles(false)
->moveFiles()
->imageEditor(),
Forms\Components\Button::make('unset_video')
->label('Unset Video')
->color('danger')
->action(fn () => $this->unsetVideo()),
])
->columns(2)
->collapsible()
->collapsed(),

public $unsetPhoto = false;
public $unsetVideo = false;

public function unsetPhoto()
{
$this->unsetPhoto = true;
}

public function unsetVideo()
{
$this->unsetVideo = true;
}
The case is to store temporary boolean value to update column after save in edit
5 Replies
LeandroFerreira
add to the schema
\Filament\Forms\Components\Actions::make([
\Filament\Forms\Components\Actions\Action::make('unset')
->action(function() {
//...
})
])
\Filament\Forms\Components\Actions::make([
\Filament\Forms\Components\Actions\Action::make('unset')
->action(function() {
//...
})
])
Jerome V
Jerome VOP3w ago
I decided to used toggle instead.. how can I store the record banner_file_id and video_file_id? The case is if the photo and video is unset then It will update banner_file_id and vide_file_id into null else if cancelled then retain the data
Forms\Components\Section::make('Photo')
->schema([
Placeholder::make('photo')
->content(fn ($record) => self::getImageContent($record) )
->visibleOn('edit')
->hidden(fn (?Advertisement $record, Forms\Get $get) =>
($record === null) || (!!$get('new_photo'))
),
Forms\Components\FileUpload::make('new_photo')
->image()
->storeFiles(false)
->moveFiles()
->imageEditor(),
Forms\Components\Toggle::make('unset_photo')
->label('Unset Photo')
->inline()
->default(false),
])
->columns(2)
->collapsible()
->collapsed(),
Forms\Components\Section::make('Photo')
->schema([
Placeholder::make('photo')
->content(fn ($record) => self::getImageContent($record) )
->visibleOn('edit')
->hidden(fn (?Advertisement $record, Forms\Get $get) =>
($record === null) || (!!$get('new_photo'))
),
Forms\Components\FileUpload::make('new_photo')
->image()
->storeFiles(false)
->moveFiles()
->imageEditor(),
Forms\Components\Toggle::make('unset_photo')
->label('Unset Photo')
->inline()
->default(false),
])
->columns(2)
->collapsible()
->collapsed(),
LeandroFerreira
_how can I store the record banner_file_id and video_fileid What does it mean?
Jerome V
Jerome VOP3w ago
I don't know if it is the right approach but the case is on edit the PM wanted to have unset (toggle) on photo and video. The purpose on this is to make the fields banner_file_id and video_file_id if save changes and if not it will just retain the data I don't want to make the fields null directly in case the edit is cancelled
krekas
krekas3w ago
maybe use observer then and update to null if needed there
Want results from more Discord servers?
Add your server