sweetalert icon indicating copy to clipboard operation
sweetalert copied to clipboard

tab is not working in the form when sweet alert is pop up

Open atulintel opened this issue 9 years ago • 22 comments

I am using sweet alert in the html form which is popup on button click but the when i click on ok button of popup, the tab index does not work after that and i have to click each and every field to fill it.

atulintel avatar Jun 27 '15 14:06 atulintel

The same think happens to me.

mfontolan avatar Jul 10 '15 12:07 mfontolan

Yup, happens to me as well. Also, hitting enter to dismiss the pop up removes the focus from the page and you cannot focus on the page again without clicking.

krishnr avatar Aug 06 '15 18:08 krishnr

remove window events in doneFunction resolve this.

swal({
  title: "Are you sure?",
  text: "You will not be able to recover this imaginary file!",
  type: "warning",
  showCancelButton: true,
  confirmButtonColor: "#DD6B55",
  confirmButtonText: "Yes, delete it!",
  closeOnConfirm: false
}, function(){

  // remove these events;
  window.onkeydown = null;
  window.onfocus = null;

  swal("Deleted!", "Your imaginary file has been deleted.", "success");
});

fxghqc avatar Aug 13 '15 08:08 fxghqc

@fxghqc removing event handlers in the callback works for me. Can this be included in the main code to prevent this bug?

ecwyne avatar Sep 18 '15 19:09 ecwyne

+1

henry74 avatar Oct 07 '15 15:10 henry74

When will this be fixed?

ShlomoRosenheimer avatar Nov 16 '15 09:11 ShlomoRosenheimer

+1

knownAsKyle avatar Dec 02 '15 02:12 knownAsKyle

Is there any fork of this bug I can work with ? I am not sure how to use @xiaouze88's commit. I'm having annoying issues regarding this bug as well.

edi avatar Jun 22 '16 10:06 edi

This bug still exists. You can even see it on the main sweetalert demo page... http://t4t5.github.io/sweetalert/

Simply click the Try Me button for the AJAX example and then notice that tab no longer works. I can see in the debugger that window.onfocus is not being restored to null afterwords. If I manually set it then I can use tab again. But setting it to null in the callback function passed to swal() does NOT work for me. I set it to null there, but something else internal to Sweetalert is setting it back before the whole process ends. Breaking into the debugger several seconds later confirms this.

Please fix!

jeffbromberger avatar Nov 02 '16 02:11 jeffbromberger

I can confirm this behavior as well. It's intermittent, the best type of bug... I am seeing the window.onkeydown event being bound to the function even after dialogs have closed... and possibly even before a dialog has been triggered.

mhoffmeyerDC avatar Dec 19 '16 17:12 mhoffmeyerDC

I am experiencing the exact same issue as well. When the SweetAlert pop-up is closed, tabs in the page's form stops working even with tabindex set.

Mr-Anonymous avatar Jan 03 '17 19:01 Mr-Anonymous

I will make a PR tomorrow with a fix for this. On Tue, 3 Jan 2017 at 21:15, Neel [email protected] wrote:

I am experiencing the exact same issue as well. When the SweetAlert pop-up is closed, tabs in the page's form stops working even with tabindex set.

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/t4t5/sweetalert/issues/391#issuecomment-270197639, or mute the thread https://github.com/notifications/unsubscribe-auth/AHWwZbRIQD1HLSs4WpN87HRyeBlvGgcuks5rOp43gaJpZM4FNSiU .

edi avatar Jan 03 '17 19:01 edi

That will be really great @EduardJS Thank you for that.

For now I am using the solution from @JustinWinthers in another thread:

(function (){

    var _swal = window.swal;

    window.swal = function(){

        var previousWindowKeyDown = window.onkeydown;

        _swal.apply(this, Array.prototype.slice.call(arguments, 0));

        window.onkeydown = previousWindowKeyDown;

    };

})();

REF: https://github.com/t4t5/sweetalert/issues/127

Mr-Anonymous avatar Jan 03 '17 20:01 Mr-Anonymous

@Mr-Anonymous update

var _swalclose=window.swal.close; var _swal = window.swal; window.swal = function(){ var previousWindowKeyDown = window.onkeydown; _swal.apply(this, Array.prototype.slice.call(arguments, 0)); window.onkeydown = previousWindowKeyDown; }; window.swal.close=function(){ _swalclose.apply(this); };

edwin1217 avatar Feb 24 '17 19:02 edwin1217

Wow! I just found this thread. I spent days on wondering why my tabs work and then they don't. Now I realize that sometimes I use a sweetalert and that's the reason it stopped!

Is anyone still working on a fix for this and what's the best solution to deal with it for now?

Edit: just saw the sweetalert2 message above. I didn't know there is another version, so I will give it a go, but there is quite a bit of work to be done to migrate!

steve-rhodes avatar Feb 25 '17 15:02 steve-rhodes

@elasticsteve If you pay attention to the other threads on this repo you will notice this one is not maintained anymore.

There is another repo called SweetAlert2, which you should really port your apps towards.

If you still want to use this version though, the only solution is this one. I forgot to make a PR.. didn't have enough time. @edwin1217's solution is the one you should go with.

edi avatar Feb 25 '17 15:02 edi

@edwin1217's solution is nearly the same i have posted in thread #127 a while ago.

kosst avatar Feb 25 '17 15:02 kosst

Thanks everyone. I tried to port over to SweetAlert2, but had to give up. I couldn't make a simple text input with closeOnConfirm: false work. After wasting 3 hours I reverted back and will try the suggestions above.

steve-rhodes avatar Feb 25 '17 17:02 steve-rhodes

@kosst Yes, your solution is much better, because with the one from @edwin1217 the default Enter key action for OK and error messages (input text modals) wouldn't work.

Here again what's working for me best:

(function (){
    var close = window.swal.close;
    window.swal.close = function() {
        close();
        window.onkeydown = null;
    };
})();

steve-rhodes avatar Feb 26 '17 02:02 steve-rhodes

}

I know it's been a really long time, but would you be kind enough to explain as to how I can call this function as a whole in another function? Where should I place this snippet in controller?

function(isConfirm){  //Function that triggers on user action.
        if(isConfirm){
          $scope.myData.splice(index,1);
          SweetAlert.swal("Deleted!");
        } else {
            SweetAlert.swal("Your file is safe!");
        }

Omniscience619 avatar May 24 '19 04:05 Omniscience619

change - closeOnConfirm: false TO - closeOnConfirm: true

that's it... it worked for me

khoiwalvikram2 avatar Jan 22 '20 17:01 khoiwalvikram2

Hi everyone, I know it has been long but did any of you found a solution for this? I am still experiencing the same problem with Angular 12.

Trend20 avatar Sep 28 '21 12:09 Trend20