OnSubmit pop-up Dialoguebox is auto closing in Catalog Client Script

smanjulavil
Tera Contributor

Hi Experts,

I have following catalog client script that executes on "onSubmit". I do get the dialogue box but it auto closes. Not sure whey this is happening. Can you give some guidance on this please. Here is my Catalog client script.

 

Note:- I did try attaching this Catalog client script other catalog items and the behavior is the same.

 

function onSubmit() {
var gFormAlreadySubmitted = false;
if (gFormAlreadySubmitted)
return true;
showConfirmationDialog();

function showConfirmationDialog() {
var dialog = new GlideModal("glide_confirm_basic_2", true, 600);
dialog.setTitle("Sample Title");
dialog.setPreference('warning', true);
dialog.setPreference('title', "A default profile already exists. This action will update the current profile as a default profile.");
dialog.setPreference('onPromptComplete', confirm());
dialog.setPreference('onPromptCancel', cancel());
dialog.render();
}

function confirm() {
gFormAlreadySubmitted = true;
g_form.submit();
}

function cancel() {
return false;
}

3 REPLIES 3

Tushar
Kilo Sage
Kilo Sage

Hi @smanjulavil 

 

The issue that you are facing is that the onSubmit() client script is being executed before the confirmation dialog has a chance to close.

This is because the onSubmit() client script is executed immediately after the user clicks the submit button, while the confirmation dialog is asynchronous and takes some time to render.

 

 

function onSubmit() {
var gFormAlreadySubmitted = false;
if (gFormAlreadySubmitted)
return true;

showConfirmationDialog();

function showConfirmationDialog() {
var dialog = new GlideModal("glide_confirm_basic_2", true, 600);
dialog.setTitle("Sample Title");
dialog.setPreference('warning', true);
dialog.setPreference('title', "A default profile already exists. This action will update the current profile as a default profile.");
dialog.setPreference('onPromptComplete', function() {
gFormAlreadySubmitted = true;
g_form.submit();
});
dialog.setPreference('onPromptCancel', cancel());
dialog.render();
}

function cancel() {
return false;
}
}

 

 

Please, don't forget to mark my answer as correct if it solves your issue or mark it as helpful if it is relevant for you!

Regards,
Tushar

Hi Tushar,

Thanks for the reply. I did try the code segment that you provided, That did not make any change in the behavior. Submit process did not wait for the confirmation from the dialogue box. System auto closed the dialogbox.

 

I tried something similar and even tried g_form.submit() as well as some g_scratchpad conditionals without success. I kept either getting a loop for my OnSubmit client script or nothing would happen.

The main piece though is having a return false after the dialog.render() because otherwise there's nothing telling the record to wait on writing to the server data.

Here's what ended up working for me:

 

 

	if(g_scratchpad._action_confirmed) {
		return true;
	}
	
	var dialog = new GlideModal('glide_modal_confirm', false, 300);
	dialog.setTitle(new GwtMessage().getMessage('Confirmation'));
	dialog.setPreference('body', new GwtMessage().format("Are you sure to save?"));
	dialog.setPreference('focusTrap', true);
	dialog.setPreference('onPromptComplete', doComplete);
	dialog.setPreference('onPromptCancel', doCancel);
	
	dialog.render();
	
	return false;
	
	function doComplete() {
		g_scratchpad._action_confirmed =  true;
		gsftSubmit(null, g_form.getFormElement(), g_form.getActionName());
	}
	
	function doCancel() {
	}

 


Full credit to icerge on GitHub who came up with this one. I spun around with different ways to try to use gsftSubmit to get this to work. 
Using modal windows in SN: GlideModal, confirm onSubmit · GitHub

You can certainly modify it to do or say what you'd like for your use case.