Is there a way to have a confirmation dialogue on ToggleColumn on table?

I was looking for a confirmation modal for this component but I could not find any? Is it supported, or how could I achieve this?
Tables\Columns\ToggleColumn::make('availability')
->onColor('success')
->getStateUsing(fn (Product $record) => $record->status == ProductStatus::ACTIVE)
->updateStateUsing(function (Product $record, bool $state) {
$record->update([
'status' => $state
? ProductStatus::ACTIVE
: ProductStatus::PAUSED
]);
}),
Tables\Columns\ToggleColumn::make('availability')
->onColor('success')
->getStateUsing(fn (Product $record) => $record->status == ProductStatus::ACTIVE)
->updateStateUsing(function (Product $record, bool $state) {
$record->update([
'status' => $state
? ProductStatus::ACTIVE
: ProductStatus::PAUSED
]);
}),
8 Replies
Kenneth Sese
Kenneth Sese2y ago
I don’t believe this is supported. The requiresValidation method isn’t available on the ToggleColumn. Also I’m pretty sure I recall someone on core team a little while ago answering a similar question and wondering why someone would need a confirmation on a ToggleColumn since if they make a mistake they can just change it back. It’s shouldn’t be destructive. And that if it needs a confirmation it should probably be done on the edit page/modal. Not sure if there was ever resolution on that conversation. Maybe search in the chat.
Dan Harrin
Dan Harrin2y ago
you can use an column action() instead of a togglecolumn which can open a amodel but yes, i dont understand why you would not just click it again
Crylar
CrylarOP2y ago
In my case, I have some resets going on a model observer, so confirmation with an explanation is a must for the user. If it was just a simple true / false toggle then yes but I have a valid edge case / reason to have this available here too. 🙂 Correct me but I am not sure if we have a toggle action right now? Yeh I know this could be done on the edit page/modal but I have a simple form for restaurant staff going where it would be very uncomfortable for them to move around the CRUD, so the idea was to have it all that is used frequently available on the table but there is an edge case where I would want to have a confirmation dialog when he is trying to change from a particular state. 🙂
Kenneth Sese
Kenneth Sese2y ago
Totally understandable. I’d create your own custom column and extend the ToggleColumn and see if you can get confirmation working. And if so maybe submit a PR for it. That’s 2 requests in a short time so maybe it’d be helpful to others. But for the meantime a customColumn could probably accomplish what you want.
Crylar
CrylarOP2y ago
Yeh, I guess this could work, just need to dive deeper into the code. :))
Kenneth Sese
Kenneth Sese2y ago
👍👍 DM me if you get stuck and I can help out.
Crylar
CrylarOP2y ago
Thanks, I will do. 🤝
Bene Richi
Bene Richi14mo ago
Hey guys! I'm facing the same problem. In my case whenever I toggle the ToggleColumn on a table item to "true" it triggers a DELETE request to a third-party tool. The issue arises when I unintentionally toggle the button, as there's no straightforward way to undo the actions triggered by the toggle. Adding a confirmation modal to the ToggleColumn would be a helpful solution.

Did you find this page helpful?