Prevent form from submitting until Modal is closed in onSubmit client script

Mark Endsley
Tera Guru

In the service portal we would like to start using Modals instead of alerts. One issue I'm having is when I write a script like this:

function onSubmit() {
   
	   if (typeof spModal != 'undefined') {


       spModal.open({


           message: 'Hello',


           title: ''


       });


   } else {


       var gm = new GlideModal();


       gm.setTitle('');


       gm.renderWithContent('Hello');


   }



   
}

 

In the service portal after pushing submit, the form will submit after a few seconds without the user having pushed ok or closing the modal.

Is there any way to get it to perform more like an alert, requiring the modal to be closed before it submits and moves on to the next page?

1 ACCEPTED SOLUTION

Mark Endsley
Tera Guru

I have finally solved this problem by using g_scratchpad

 

	if (typeof spModal != 'undefined') {
		
		if (g_scratchpad.isFormValid) {
			return true;
		}
		
		
		spModal.open({
			
			
			message: 'HELLO',
			
			
			title: ''
			
			
			
			
		}).then(function(confirmed){
			
			g_scratchpad.isFormValid = true;
			
			var actionName = g_form.getActionName();
			
			 g_form.submit(actionName);
			
			return true;});
			
			
			g_scratchpad.isFormValid = false;
			return false;
			
			
			
		} else {
			
			
			var gm = new GlideModal();
			
			
			gm.setTitle('');
			
			
			gm.renderWithContent('HELLO');
			
			
		}

View solution in original post

13 REPLIES 13

Hi Brandon,

Neither of the solutions listed in that thread works. The form still submits before the user has pushed Ok.

Ah apologies, I will ask around, and if I get a decent answer will return!

Mark Endsley
Tera Guru

I have finally solved this problem by using g_scratchpad

 

	if (typeof spModal != 'undefined') {
		
		if (g_scratchpad.isFormValid) {
			return true;
		}
		
		
		spModal.open({
			
			
			message: 'HELLO',
			
			
			title: ''
			
			
			
			
		}).then(function(confirmed){
			
			g_scratchpad.isFormValid = true;
			
			var actionName = g_form.getActionName();
			
			 g_form.submit(actionName);
			
			return true;});
			
			
			g_scratchpad.isFormValid = false;
			return false;
			
			
			
		} else {
			
			
			var gm = new GlideModal();
			
			
			gm.setTitle('');
			
			
			gm.renderWithContent('HELLO');
			
			
		}