Confirmation Modal Utility: Ability to use in JS Query like notifications

It would be a really neat feature if we could trigger a confirmation modal within a JS Query like how we can with notifications.

For example, if we could do something like this:

utils.showConfirmation({
    title: 'Please Confirm';
    description: 'Are you sure you want to <take specific action>?';
    actions: {
        acceptOptions: {
            text: 'Confirm'
            background: {{ `${theme.warning}` }},
            color: '#FFFFFF'
        },
        cancelOptions: {
            text: 'Cancel'
            background: {{ `${theme.canvas}` }},
            color: '#FFFFFF'
        }
    } 
})
3 Likes

AJ! I should send this over teams too so check there but here is an idea you could try.

utils.confirm({
title: 'Please Confirm',
description: 'Are you sure you want to take the specific action?',
acceptLabel: 'Confirm',
cancelLabel: 'Cancel',
onConfirm: () => {
// Code to execute if the user confirms
console.log('Confirmed!');
// Place your action code here
},
onCancel: () => {
// Code to execute if the user cancels
console.log('Cancelled');
}
});

You may be able to trigger a modal or confirmation prompt using utils.showNotification or utils.confirm, but utils.showConfirmation is not a built-in function. To achieve the desired behavior, you can use utils.confirm for a simple confirmation dialog. If you try this out Iā€™m interested in hopping on a call and seeing your use case.

Ay carumba...is utils.confirm seriously a utility included in Retool and this whole time I just missed it!? :flushed: Haha I was aware that utils.showConfirmation is not an available utility which is why I had it in Feature Requests, I just wanted to be able to have access to something like the sweetAlert2 library so we could designate confirmations as well as other notification types with a simple JS method natively usable from the utility level.

But it sounds like it may already exist? I'm blown away I never noticed it :laughing: I've built a confirmation modal previously, but wanted to be able to do it without self-built custom logic. I'm gonna look into utils.confirm though! :fist: Thanks man!

Hey all! This is a neat idea and something I'm happy to pass on to the team. :+1:

I don't think utils.confirm is a thing in the current build, but it is possible to dynamically require user confirmation before running a query:

As such, I imagine it should be relatively straightforward to turn this into a utils method!

2 Likes

That would be awesome! There are occasions where I'd want to pop a confirmation like a notification during a process within a JS Query where advanced settings in a query wouldn't be conventional. Let me know if this gets added and thanks for the reply @Darren!!!

1 Like

Hi @Darren - when the user clicks "cancel" on the confirmation, is there any way to return that back as the result of the query? I think it currently just doesn't execute. Would be much better if the "cancel" would send something back that you can use in a branch. For example, if changing a switch value would trigger a query that maybe a user doesn't want to trigger, it would be great if clicking "cancel" on the notification would send something back that would let me re-set the switch.