Using isConfirm with a SweetAlert

Crystal Rouse
Crystal Rouse used Ask the Experts™
on
I have a SweetAlert with a Cancel option.  My javascript has the isConfirm function and works correctly if isConfirm is true.  It just bypasses the code for the else statement. Any thoughts?

 swal({
                title: "Add New Action/Task",
                text: "This will add a new Action/Task to the stored Action List for future use.  If you do not wish to save this Action for later, click Cancel and choose Other.",
                type: "warning",
                showCancelButton: true,
                cancelButtonText: "Cancel",
                buttons: true,
                dangerMode: true,
                closeOnConfirm: true,
                closeOnCancel: true,
                confirmButtonText: "Yes"
            },
                function (isConfirm) {

                    if (isConfirm) {
                        CM.disabled = false;
                        CM.style.backgroundColor = "white";
                        actionOther.style.backgroundColor = "white";
                        actionOther.placeholder = "Enter New Action/Task";
                    }

                    else {
                        CM.disabled = false;
                        actionDropdown.value = "Other";
                        actionDropdown.text = "Other (Enter Other Action/Task)";
                        actionOther.placeholder = "Enter Other Action/Task";
                    }

                }.bind(this));

Open in new window

Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Developer & EE Moderator
Fellow 2018
Most Valuable Expert 2013
Commented:
I have not yet used SweetAlert, but have it bookmarked to try it out.  

I did see that isConfirm is from a previous version.  https://github.com/sweetalert2/sweetalert2/wiki/Migration-from-SweetAlert-to-SweetAlert2

swal(
  {title: 'Are you sure?', showCancelButton: true}, 
  function(isConfirm) {
    if (isConfirm) {
      // handle confirm
    } else {
      // handle all other cases
    }
  }
)

Open in new window

becomes a promise
swal({title: 'Are you sure?', showCancelButton: true}).then(result => {
  if (result.value) {
    // handle Confirm button click
    // result.value will contain `true` or the input value
  } else {
    // handle dismissals
    // result.dismiss can be 'cancel', 'overlay', 'esc' or 'timer'
  }
})

Open in new window


My question is which version are you using?
Crystal RouseTask Lead

Author

Commented:
We have probably one of the very first versions. We've never upgraded it.
Crystal RouseTask Lead

Author

Commented:
I fixed it myself.  Simply replaced: }.bind(this));
with });
Ensure you’re charging the right price for your IT

Do you wonder if your IT business is truly profitable or if you should raise your prices? Learn how to calculate your overhead burden using our free interactive tool and use it to determine the right price for your IT services. Start calculating Now!

Crystal RouseTask Lead

Author

Commented:
I fixed it myself.  Simply replaced: }.bind(this));
 with });
Crystal RouseTask Lead

Author

Commented:
I fixed it myself.  Simply replaced: }.bind(this));
 with });
Varun WaliaPHP developer

Commented:
sweetAlert is used in older versions.

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial