sweetalert icon indicating copy to clipboard operation
sweetalert copied to clipboard

Cancel button still showing on confirmation

Open georgecoca opened this issue 10 years ago • 7 comments

Hi,

I noticed that if I use default config like this one:

swal.setDefaults({
    showCancelButton: true
});

the Cancel button still showing when this is executed:

swal("Success!", "Your data has been saved.", "success");

Image

... but if I remove showCancelButton from setDefaults and add it to the swal function config like this:

swal({
    title: 'Enter your name',
    text: 'Enter your name',
    type: "input",
    showCancelButton: true,
}

the Cancel button doesn't show up anymore, which is the expected behaviour.

Image

I guess this is a bug.

georgecoca avatar Nov 03 '16 18:11 georgecoca

Hey @geodeveloper

Do you have a callback function after the input swal?

If so, I assume you have another swal as the success message, which has its own settings (none of which are inherited by its parent). You would have to redeclare the showCancelbutton property.

ryanvaness avatar Jan 23 '17 01:01 ryanvaness

Hi @fallen-rve, Yes I have a callback function. I've took the example of input from official sweetalert website and just added the default config on top. Take a look here --> https://jsfiddle.net/a836z9xv/ so you can see the bug.

Thanks for your time.

georgecoca avatar Jan 24 '17 16:01 georgecoca

@geodeveloper gotcha!

That is the expected behavior of setDefaults. If you set the setDefaults property, it'll apply to all of your SweetAlerts, regardless if it's the shorthand or longhand versions.

From the documentation:

If you end up using a lot of the same settings when calling SweetAlert, you can use setDefaults at the start of your program to set them once and for all!

Let me know if that clears it up.

Thanks!

ryanvaness avatar Jan 29 '17 00:01 ryanvaness

As @ryanvaness pointed out, this is indeed the expected behaviour. :) Don't use setDefaults unless it applies to all your alerts!

t4t5 avatar Sep 07 '17 20:09 t4t5

@ryanvaness, @t4t5 thanks for the reply (and sorry for my late response),

I see what you mean and it makes sense, I was confused because I thought if I pass the showCancelButton to the swal function will override the default setting.

swal({
    title: 'Enter your name',
    text: 'Enter your name',
    type: "input",
    showCancelButton: true, <-- should override the default setting? 
}

and the default setting should apply only if there is no override setting passed to swal.

But if this was the expected behaviour then I would have to change the way I use the cancel button.

Thanks again!

georgecoca avatar Sep 08 '17 06:09 georgecoca

@geodeveloper Hmm, that should indeed override the user defaults, so if it does not then it seems like a bug. Using the the buttons option in SweetAlert 2.0 is probably more reliable now :)

t4t5 avatar Sep 08 '17 06:09 t4t5

@t4t5 I just checked and indeed it overrides correctly, I think I had some issues with the configuration. All works great, thanks!

georgecoca avatar Sep 08 '17 06:09 georgecoca