Andrew Willis
Andrew Willis

Reputation: 2349

Bootstrap 3 remove modal trigger

I have a modal which I use to sign users in or sign them up to my site. I also allow joining through Facebook.

Now, when a native session expires on my site, I don't want to automatically sign the user in through Facebook unless they distinctly tell me to, which means that I am triggering the sign-in when they click the link which triggers the modal.

The problem I am having is that the modal still fires (and then gets hidden straight away) and I was wondering if there was a way in which I could remove the modal trigger if the user has connected through Facebook, and instead, when they click the modal trigger it just signs them in.

I have tried this to no avail.

FB.getLoginStatus(function(response) {
    if (response.status === 'connected') {
        $('#sidebar-auth-modal-trigger').off('click.bs.modal.data-api');
        $(document).off('click.bs.modal.data-api', '#sidebar-auth-modal-trigger');

        ...

    }
});

Upvotes: 0

Views: 290

Answers (1)

cjd82187
cjd82187

Reputation: 3593

Since you mentioned you're using their data-attributes, remove that from your html.

Try only triggering the modal when your FB status is what you want, like this (I don't really know what your FB login status is doing, not all the code is there, but this should get you on your way):

FB.getLoginStatus(function(response) {
    if (response.status === 'connected') {
       //dont call your modal here if you dont want it

    } else {
        //call your modal
        $('#myModal').modal();
    } 

});

$('#sidebar-auth-modal-trigger').on('click', FB.getLoginStatus);

Now it will only call the modal when your facebook status is what you want it to be, and it won't when its not.

Upvotes: 1

Related Questions