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 Harrin2y ago
its not possible to override on a view page. theres no way to save the data anyway
Crylar
CrylarOP2y 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 Harrin2y ago
yes, but if the button isnt movable then it wont work
Crylar
CrylarOP2y 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 Harrin2y ago
ViewAction::make() you dont need any of this ViewAction::make()->disableForm(false)
Crylar
CrylarOP2y 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 Harrin2y ago
is this a modal or a page
Crylar
CrylarOP2y ago
edit is page, and view is modal
Dan Harrin
Dan Harrin2y ago
i dont know then something doesnt make sense here
Crylar
CrylarOP2y 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
CrylarOP2y 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 Harrin2y ago
override it then
Crylar
CrylarOP2y ago
Yeh, I did this. Finally got things to work, not as nicely though. 🙂
Dan Harrin
Dan Harrin2y 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
CrylarOP2y 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 Harrin2y ago
yeah we call view by default or edit if view doesnt exist but you can override getTableRecordAction()
Crylar
CrylarOP2y 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
CrylarOP2y 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