Submit Confirmation Prompt

I have created a profile input forms. Then I have added a update page as well. I have a submit button to save the info that they have updated but what I am missing now is a confirmation prompt that they really want to update their profile. Is there any way I can do that?

Hay Farmshare,

If I understand you right, you want to have a dialog, when a user clicks the save button, asking “are you sure” with an ok and cancel buttons?

If this is the case, you will need a bit of coding. What you can do is

  1. Instead of connecting the button to the dataset save action, register an onClick event on the button.

  2. In the onClick event handler trigger the dialog with the message. The dialog can be either a box that you show with two buttons on top, or a lightbox with two buttons.

  3. If using a lightbox, make sure to shutdown the close button and the X button. Add your own two buttons for ok and cancel.

  4. on clicking the ok button in the dialog you can call the dataset .save API.

This will look something like the following - using a lightbox -

import wixWindow from 'wix-window';

export function BUTTON1_onClick() {
  wixWindow.openLightbox('LIGHTBOX')
    .then(res => {
      if (res === 'ok')
        $w('#DATASET').save();
    });
}

and in the lightbox code

import wixWindow from 'wix-window';

export function OK_BUTTON_onClick() {
  wixWindow.lightbox.close('ok');
}

export function CANCEL_BUTTON_onClick() {
  wixWindow.lightbox.close('cancel');
}

Hi Yoav,
Thanks for your quick reply. Your assumptions are right. That’s what I needed. I have tried using your code but it doesn’t trigger the lightbox to appear.

Correct me if i am wrong, ‘LIGHTBOX’ is the ID of the lightbox and #DATASET is the id of my Dataset.

I tried putting only wixWindow.openLightbox(‘LIGHTBOX’) but still nothing happens. Does it work in Preview mode?

p.s. underscore is not allowed value in ID :slight_smile:

Hi again Yoav. Sorry my mistake. ‘LIGHTBOX’ is the the name of the ligthbox page. :slight_smile: It is working now.

Thank you very much!

Hi,
You need to use wixLocation.to method.
Check this out:

Good luck!
Roi

do you have import wixLocation from ‘wix-location’; declared on top?

maybe you can share your code :slight_smile:

Hi Tween,
Did you manage to get it work ?
Roi

Good job!

Hi,
Sorry, I got confused with something else. Can you please share your form link so i can be inspect more thoroughly?
Roi

Yes ,there is. The dataset´s onError object returns a message containing the words ‘validation failed’ in this case. So you check on that and act accordingly. I will give you a piece of my code to show how it works, hope this helps:
The boxPleaseWait is a spinner I put up when saving, so you can ignore that. What the thing does is look for the specific erro and put up lightbox A. If another error, lightbox B.
Have fun.

$w(“#dynamicDataset”).onError( (operation, error) => {
let errorOp = operation;
let errorObj = error;
let errorMessage = errorObj.message;
if (errorMessage.indexOf(“validation failed”) > 0) {
$w(“#boxPleaseWait”).hide();
wixWindow.openLightbox(“Err:HayErrores”);
$w(“#btnSave”).enable();
$w(“#btnCancel”).enable();
}
else {
$w(“#boxPleaseWait”).hide();
wixWindow.openLightbox(“Err:Data”, errorObj );
$w(“#btnSave”).enable();
$w(“#btnCancel”).enable();

} 

} );

I know this is a very old conversation, but in case anybody is still listening: The problem with the suggested solution is that a good confirmation dialog is modal, that is, you have to interact with it before doing anything else. With the suggested solution, you see the confirmation box and buttons just fine, but nothing stops the user from clicking other buttons or taking other actions without ever clicking on OK or CANCEL. Maybe ignoring the confirmation dialogue is equivalent to clicking CANCEL (except that the box and buttons don’t disappear!) but it’s certainly a suboptimal experience and it’s easy to see ways that it can cause problems.

I’m looking for the same thing, and just wondering if some better solution has been provided. (Please don’t tell me to disable all my controls before making the confirm controls visible and re-enabling them later; this isn’t feasible.) I’m a little surprised that such a dialog box isn’t built-in to WiX—it’s even a Javascript built-in most places, since it’s so useful in so many situations.

Hello Larry,

You should better open your own post with your own issue, and link it with this post.
Describe detailed your situation and give as most as pissible informations to your issue. I am sure someone will help you out.