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!? 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 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! Thanks man!
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!!!
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.
Interesting. I was thinking more about having control within the query that I am getting confirmation for, but creating a wrapper like this does open up possibilities. I imagine in general it would be something like:
let askUser = await coolButDestructiveQuery.trigger();
if (x) {
return coolButDestructiveQuery.data
} else {
// Leave everything the way you found it, maybe notify the user
return utils.showNotification({
title: "Whew!",
description: "That was a close one!",
notificationType: "Info",
});
}
But what if I want this to be on the submit of a form? I guess instead of using the "reset form on successful submit" button, since the wrapper will "submit" successfully either way, I would need to script it into my actions on user clicking yes (form would be left as is if the user clicks no since I unchecked the box).
Absolutely! I actually have created something similar -- in which there's an app I created for our company where at the details page of an employee, you have an option to "terminate" them on a selected date by clicking a button that opens a date picker in a modal. If you terminate them, it runs a JS query that simply opens another modal.
In that modal, there is a form where you can select whether or not to terminate them by clicking 'Confirm' or 'Cancel'.
If the end user clicks 'Confirm', it fires the update query which contains the changeset data to terminate them from the previous form with the date picker -- in which at that time I clear that form 'on success' of the update query.
But it would be much simpler to just have an option in a JS query to use something like utils.showConfirmation({}) like how you would use utils.showNotification({}).
Hi @TRF i tried this 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');
} it doesn't work
Hey @Tosin_Akinde! I think that particular code sample is more of a hypothetical, as utils.confirm is not a valid function. The team is aware of the interest in such a feature, but it hasn't yet been prioritized. I'll update this thread as soon as there is news to share.