This topic is locked
[SOLVED]

 10.5 and SWAL

1/5/2021 9:19:34 PM
PHPRunner General questions
G
GBH author

I am trying to implement a SWAL version of the following in my custom button Client Before event
This works fine
var r = confirm("Are you sure?");

if (r == true) {

return true;;

} else {

return false;

};
I have copied and pasted an example straight from the SWAL website (below), replacing the above code and have the following issues.

  1. When I click on the Check Syntax button is displays a Microsoft Jscript compilation error.
  2. Regardless, I pressed on and it fires without throwing an error, but it doesn't pause for user input (meaning than the Sever and Client After events were fired without me being able to capture a user response)
  3. I then tweaked it again, trying to set a return true/return false in place of the 2nd and 3rd SWAL displays, but regardless of what I select a return true is executed, and the SWAl displays for about a second then auto closes
    Original code from the SWAL website
    swal({

    title: "Are you sure?",

    text: "Once deleted, you will not be able to recover this imaginary file!",

    icon: "warning",

    buttons: true,

    dangerMode: true,

    })

    .then((willDelete) => {

    if (willDelete) {

    swal("Poof! Your imaginary file has been deleted!", {

    icon: "success",

    });

    } else {

    swal("Your imaginary file is safe!");

    }

    });
    Version 2, which flashes on the screen, disappears without waiting for a response, and seems to issue a return true
    swal({

    title: "Are you sure?",

    text: "Once deleted, you will not be able to recover this imaginary file!",

    icon: "warning",

    buttons: true,

    dangerMode: true,

    })

    .then((willDelete) => {

    if (willDelete) {

    return true;

    } else {

    return false;

    }

    });
    What am i doing wrong?

admin 1/6/2021

Please check the latest build 36440, .then(... ) should work there.
Just to add, the following syntax will not work in Internet Explorer:

(willDelete) => {

...

}


It should be changed this way:

function (willDelete) {

...

}


Also you can ignore syntax check errors, Microsft JScript doesn't understand this kind of syntax.

G
GBH author 1/7/2021

Sorry, I still cant get this to work.

  1. I am now on build 36478
  2. This is being fired from the custom button client before event.
  3. The SWAL popup now stays until I action it, but the Server events fire before I respond to the SWAl dialog.
    I have seen another post which which seems to indicate that this will not work from a custom buttonhere
    Is a SWAL confirmation dialog supported?

admin 1/8/2021

Take a look at this article:

https://xlinesoft.com/phprunner/docs/submit().htm
You need to return false in your ClientBefore code, this will prevent the Server event from executing. Then in your SWAL code, if user confirms the action you need to issue submit() that will start the Server part of the code.

D
david22585 1/8/2021



Take a look at this article:

https://xlinesoft.com/phprunner/docs/submit().htm
You need to return false in your ClientBefore code, this will prevent the Server event from executing. Then in your SWAL code, if user confirms the action you need to issue submit() that will start the Server part of the code.


Thank you so much for this Sergey!! I've been trying to get this to work, and you've put me on the right path to make it work now with this link!



Sorry, I still cant get this to work.

  1. I am now on build 36478
  2. This is being fired from the custom button client before event.
  3. The SWAL popup now stays until I action it, but the Server events fire before I respond to the SWAl dialog.
    I have seen another post which which seems to indicate that this will not work from a custom buttonhere
    Is a SWAL confirmation dialog supported?


This is what I was able to do to get this to work:



swal({

title: "Please confirm",

text: "Do you wish to remove this contact information from your account?",

icon: "warning",

buttons: true,

dangerMode: true,

})

.then(function(willDelete){

if (willDelete) {

submit();

swal("This contact information has been removed from your account.", {

icon: "success",

});

} else {

swal({

text: "You contact information has not been removed.",

icon: "info",

})

}

});
return false;


I put the return false; at the end so it doesn't process the server code. If you click submit, it will run the submit() function and run the server code. I gave myself a 5 second delay to refresh the page with this on the after client event:

setTimeout( function() {

location.reload();

}, 5000 );


This is a combination of Sergeys post to the manual and his tips to edit the code.

D
david22585 1/9/2021

Just wanted to add something else to this. Say you use this to delete a row on the list page, but don't want to reload the entire page, use this in the after client event:

setTimeout( function() {

Runner.runnerAJAX(Runner.pages.getUrl(pageObj.tName, pageObj.pageType)+"?a=return",

pageObj.ajaxBaseParams,

function(respObj){

pageObj.pageReloadHn.call(pageObj, respObj)

});

}, 5000 );


Make sure that you also have have "AJAX Search, pagination, and sorting" checked on the List Page Settings. This will keep the alert that your record was deleted up until you click okay on the Sweetalert dialog, but will refresh the list page with the row deleted after 5 seconds.

G
GBH author 1/12/2021

Thanks everyone for your help. Working now