craftpip / jquery-confirm

A multipurpose plugin for alert, confirm & dialog, with extended features.

Home Page:http://craftpip.github.io/jquery-confirm/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

showLoading spinner disappears immediately

salasfoor opened this issue · comments

jquery-confirm version:
v3.x.x

I'm submitting a ... (check one with "x")
[ ] bug report
[ ] feature request
[x] support request

Current behavior:

When using the prompt confirmation method, after clicking on submit, showLoading's spinner appears for a split of a second and does not continue until Ajax returned response.
Expected behavior:

The spinner should last until the response from Ajax is ready and returned.
Steps to reproduce:
Apply the code.
Related code:

var jc = $.confirm({
		title: 'Form Title',
		type: 'blue',
		content: '' +
		'<form class="formName">' +
		'<div class="form-group">' +
		'<div>Message</div>' +
		'<div><textarea name="msg" id="msg" class="msg" rows="8" maxlength="280"></textarea></div>' +
		'</div>' +
		'</form>',
		buttons: {
			formSubmit: {
				text: 'Send',
				btnClass: 'btn-blue',
				action: function () {
					
					var msg = $("#msg").val();
					
					
					$.ajax({
        				url: 'process.php',
            			        type: 'POST', 
            	      	                dataType: "json",
      					encode: true,
      					cache: false,
            			       data: {'msg' : msg},	   				
    				       }).done(function (resp) {
    					
						  console.log(resp);
						  if (!resp.status) {

								$.alert({
									rtl: true,
									title: 'Result!',
									content: '<span style="color: red;">' + resp.url + '</span>',
									type: 'red',	
									buttons: {
										cancel: {
											text: 'Back',
										}
									}
								});      
  
						  } else {

								$.alert({
									rtl: true,
									title: 'Result!',
									content: resp.url,
									type: 'green',
									buttons: {
										cancel: {
											text: 'Back',
											action: function(){
					
											}},
			
									}
								});
  
						  }

						});
						
				}
			},
			cancel: {
				text: 'Back'
			},
		},

		onAction: function () {
		jc.showLoading();
		},
		onContentReady: function () {
			// bind to events
			var jc = this;
			
			this.$content.find('form').on('submit', function (e) {
				// if the user submits the form by pressing enter in the field.			
				e.preventDefault();
				jc.$$formSubmit.trigger('click'); // reference the button and click it
				
			});
			
		}
	});

Other information: