F
Filament15mo ago
Crylar

Is it possible to enable particular component during view?

I have tried to do disabled(false) but the component remains disabled. Is it possible to override this in a view?
Forms\Components\Toggle::make('delivered')
->disableLabel()
->disabled(false)
Forms\Components\Toggle::make('delivered')
->disableLabel()
->disabled(false)
18 Replies
Dan Harrin
Dan Harrin15mo ago
its not possible to override on a view page. theres no way to save the data anyway
Crylar
Crylar15mo ago
Hm, then the other question - Is it possible to change something when e.g. user toggles on Toggle button? I mean without pressing save button but on change event. So I have the following use-case where I do save on after state updated, and would love to allow user to do this single change on view.
Forms\Components\Toggle::make('status')
->formatStateUsing(fn (Product $record) => $record->pivot_status == OrderProductStatus::DELIVERED->value)
->reactive()
->afterStateUpdated(function ($livewire, $state) {
$livewire->record->pivotProducts()->update([
'status' => $state
? OrderProductStatus::DELIVERED
: OrderProductStatus::PENDING
]);
})
->onColor('success')
->disableLabel()
Forms\Components\Toggle::make('status')
->formatStateUsing(fn (Product $record) => $record->pivot_status == OrderProductStatus::DELIVERED->value)
->reactive()
->afterStateUpdated(function ($livewire, $state) {
$livewire->record->pivotProducts()->update([
'status' => $state
? OrderProductStatus::DELIVERED
: OrderProductStatus::PENDING
]);
})
->onColor('success')
->disableLabel()
So I thought that disabled(false) should act as an inverse but can't find any use of conditional if this is not followed.
Dan Harrin
Dan Harrin15mo ago
yes, but if the button isnt movable then it wont work
Crylar
Crylar15mo ago
Tables\Actions\Action::make('view')
->action(fn (Action $action) => $action->halt())
->modalHeading(fn (Order $record) => '# ' . $record->number)
->form(function () {


}),
Tables\Actions\Action::make('view')
->action(fn (Action $action) => $action->halt())
->modalHeading(fn (Order $record) => '# ' . $record->number)
->form(function () {


}),
so maybe I am better to have a custom action here but not exactly sure how to pass an existing form schema into the modal. :/
Dan Harrin
Dan Harrin15mo ago
ViewAction::make() you dont need any of this ViewAction::make()->disableForm(false)
Crylar
Crylar15mo ago
I have tried disabledForm before writing but it did not work for some reason :/ I have even gone to source code to comment out $this->disableForm() but it looks like the disable is coming from somewhere else Edit page got my toggle enabled so this is not a form
Dan Harrin
Dan Harrin15mo ago
is this a modal or a page
Crylar
Crylar15mo ago
edit is page, and view is modal
Dan Harrin
Dan Harrin15mo ago
i dont know then something doesnt make sense here
Crylar
Crylar15mo ago
public static function form(Form $form): Form
{
return $form
->schema([
Forms\Components\Toggle::make('status')
]);
}
public static function form(Form $form): Form
{
return $form
->schema([
Forms\Components\Toggle::make('status')
]);
}
Tables\Actions\ViewAction::make()
->modalHeading(fn (Order $record) => '# ' . $record->number)
->disableForm(false),
Tables\Actions\ViewAction::make()
->modalHeading(fn (Order $record) => '# ' . $record->number)
->disableForm(false),
That's what I have and toggle is disabled in the modal view :/ I also did fresh filament install just in case
Tables\Actions\Action::make('test')
->action(fn ($action) => $action->halt())
->modalHeading(fn (Order $record) => '# ' . $record->number)
->form([
Forms\Components\Toggle::make('status')
]),
Tables\Actions\Action::make('test')
->action(fn ($action) => $action->halt())
->modalHeading(fn (Order $record) => '# ' . $record->number)
->form([
Forms\Components\Toggle::make('status')
]),
but when I do this toggle is enabled Also, if I set form then toggle is not disabled. I just can't find where ViewAction loads the form data from, maybe there is something that keeps ignoring the disableForm(false)
Tables\Actions\ViewAction::make()
->label('Products')
->icon('heroicon-o-lightning-bolt')
->disableForm(false)
->button()
->modalHeading(fn (Order $record) => '# ' . $record->number)
->form([
Forms\Components\Toggle::make('status')
]),
Tables\Actions\ViewAction::make()
->label('Products')
->icon('heroicon-o-lightning-bolt')
->disableForm(false)
->button()
->modalHeading(fn (Order $record) => '# ' . $record->number)
->form([
Forms\Components\Toggle::make('status')
]),
Crylar
Crylar15mo ago
Yeh, so this is in the ListRecord, and gets disabled ViewForm for ViewAction by default so the disableForm has no effect.
Dan Harrin
Dan Harrin15mo ago
override it then
Crylar
Crylar15mo ago
Yeh, I did this. Finally got things to work, not as nicely though. 🙂
Dan Harrin
Dan Harrin15mo ago
if i were you, forget about all this and just do an action button instead of trying to hack the form to not be disabled
Crylar
Crylar15mo ago
By the way, do you know if it's possible to have action called on table row click? I thought to use View to easily override this but I guess when I use modal it's not a case anymore.
Dan Harrin
Dan Harrin15mo ago
yeah we call view by default or edit if view doesnt exist but you can override getTableRecordAction()
Crylar
Crylar15mo ago
oh, I will give a shot ... two days till we go live on the biggest arena in Lithuania with the startup, so many questions to finalise bits, thanks.
Tables\Actions\Action::make('view')
->action(static function (): void {})
->modalHeading(fn (Order $record) => '# ' . $record->number)
->modalActions(function ($action) {
return [
$action->getModalCancelAction()->label(__('filament-support::actions/view.single.modal.actions.close.label'))
];
})
->label('Products')
->icon('heroicon-o-lightning-bolt')
->color('secondary')
->button()
->mountUsing(function (Forms\ComponentContainer $form, Order $record): void {
$data = $record->attributesToArray();
$form->fill($data);
})
->form(function (OrderResource $resource) {
return $resource::form(Form::make())->getSchema();
}),
Tables\Actions\Action::make('view')
->action(static function (): void {})
->modalHeading(fn (Order $record) => '# ' . $record->number)
->modalActions(function ($action) {
return [
$action->getModalCancelAction()->label(__('filament-support::actions/view.single.modal.actions.close.label'))
];
})
->label('Products')
->icon('heroicon-o-lightning-bolt')
->color('secondary')
->button()
->mountUsing(function (Forms\ComponentContainer $form, Order $record): void {
$data = $record->attributesToArray();
$form->fill($data);
})
->form(function (OrderResource $resource) {
return $resource::form(Form::make())->getSchema();
}),
looks to work, just not sure about the form part, looks a bit hacky
Crylar
Crylar15mo ago
@danharrin I have just opened a PR that allows ViewAction to respect disableForm(false) param. https://github.com/filamentphp/filament/pull/6381
GitHub
Respect disableForm(false) for ViewAction by linaspasv · Pull Reque...
The following PR allows to override disableForm setting on a ViewAction. Tables\Actions\ViewAction::make()->disableForm(false)
Want results from more Discord servers?
Add your server
More Posts
How to customise title in SelectFilter loaded via relationship?I have the following filter and would love to concat ``title`` with ``prefix`` field. How it's possiIs 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 Key value column implementation for settings tableI have settings table with two columns `key and value` . I want a setting resource to set multipleWhat are my options to use repeater component as collapsible element inside table?I would like to have products listed inside collapsible panel on a table with some actions attached How can I update a form input on action?I have action button on edit page and would like to update a particular input on edit form. How can File Attachment Does Not Exist on Media Library Plugin/Form BuilderHi, I don't understand why I get "File Attachment Does Not Exist" . I am using Spatie Media LibraryImage ValidationHi, I'm using fileupload, and wanted to validate the image height and width(using max or min height Default sort direction for a column - descending firstTo improve the UX I wanted to change how the ‘Updated at’ timestamp are sorted descending on first cCan I use spatie media library plugin for non-admin purposes?Can I use spatie media library plugin for non-admin purposes?How to Manage Post Status, Schedule, and Publish Date in Laravel Filament with WordPress-like FunI'm building a blog application using Laravel Filament and I need to implement a feature that allows