Ivan
Ivan

Reputation: 1241

How to fade out error prompts with Validation Engine Plug in for jQuery?

I'm using from it https://github.com/posabsolute/jQuery-Validation-Engine

I wonder how to make the prompts should to close themselves by 4 seconds without clicking the prompts to closethe code line is 26 from jquery.validationEngine.js, it looks like:

$(".formError").live("click", function() {
    $(this).fadeOut(150, function() {
        // remove prompt once invisible
       $(this).remove();
    });
});

I tried to remove "click" inside of live, but it didn't work because the validations don't appear, anyone can help me? Thanks in advance!

Upvotes: 0

Views: 6338

Answers (2)

Fowowski
Fowowski

Reputation: 132

Use the autohide option. Check the documentation of validationEngine or the validationEngine.js - at the bottom of the .js file you'll see:

    // Auto-hide prompt
    autoHidePrompt: true,
    // Delay before auto-hide
    autoHideDelay: 3000,
    // Fade out duration while hiding the validations
    fadeDuration: 0.3

Upvotes: 5

Indigenuity
Indigenuity

Reputation: 9740

I'm guessing you're trying to make sure the "click" event only happens once? If so, use unbind() to undo all event listeners. If you want to be specific about which event listener, use a parameter: unbind("click") like this:

$(".formError").live("click", function() {
$(this).unbind("click");
$(this).fadeOut(150, function() {
    // remove prompt once invisible
   $(this).remove();
});

});

When the unbind("click") is called, that particular .formError element will no longer have the click event listener, but all the others still will.

EDIT: When unbinding all events tied to event listeners initialized with live(), you must use die(). Sorry, I hadn't live()'d in a while, so I forgot you had to die().

Upvotes: 1

Related Questions