Mehdi
Mehdi

Reputation: 31

forms not submitted after an unbind

I'd like that the visitors who are not logged into my website have a login popup displayed when they click anywhere on the page. I'm using jQuery to do that with

$('body.no-auth a, body.no-auth span, body.no-auth ul, body.no-auth li, body.no-auth p').unbind('click');
$('body.no-auth a, body.no-auth span, body.no-auth ul, body.no-auth li, body.no-auth p, body.no-auth input').click(function(event) {
    event.preventDefault();
    $('#sign-up-overlay').fadeIn('slow');
    $('#login-form').css('margin', ( ( window.innerHeight-$('#login-form').height() )/2 )+"px 0 0 0");
});

It works, my popup is displayed but I can't submit the login form (It's submitted with $.ajax). When I click on the submit button, nothing append...

Did I forgot something ?

Upvotes: 2

Views: 51

Answers (1)

Halcyon
Halcyon

Reputation: 57728

Once you load the popup disable this handler because it keeps triggering and cancelling your clicks.

One way to do it is:

var popup_open = false;
$('body.no-auth a, body.no-auth span, body.no-auth ul, body.no-auth li, body.no-auth p, body.no-auth input').click(function(event) {
    if (popup_open === false) {
        event.preventDefault();
        $('#sign-up-overlay').fadeIn('slow');
        $('#login-form').css('margin', ( ( window.innerHeight-$('#login-form').height() )/2 )+"px 0 0 0");
    }
    popup_open = true;
});

Make sure you set popup_open to false when you close it.

Upvotes: 2

Related Questions