Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix problem when using typewatch with JSF and AJAX #38

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

rlanhellas
Copy link

In JSF, when AJAX is called, the jquery-plugins need to be restarted everytime (using jsf.ajax.addOnEvent) and it cause problem in typewatch plugin, because events (keydown, paste,cut and input) are called multiple times. So, if this event hit a database, the database is called multiple times causing a lot of problems (poor performance application).

To solve it, i added a name for each event (keydown.typewatch, paste.typewatch ...), and you can unbind just this event to restart typewatch, like this code:

$(document).ready(function () {
jsf.ajax.addOnEvent(restartTypewatch);
});

function restartTypewatch(){
//unbind all events to avoid multiple calls
$('#my-input-text').unbind('keydown.typewatch paste.typewatch cut.typewatch input.typewatch');

//start typeWatch again
$('#my-input-text').typeWatch(options);
}

You can't unbind all "keydown" events because it will cause problems in another jquery-plugins, like this:


//unbind all keydown in this component can cause problem in others plugins, better unbind just typewatch
$('#my-input-text').unbind('keydown');

…everytime (using jsf.ajax.addOnEvent) and it cause problem in typewatch plugin, because events (keydown, paste,cut and input) are called multiple times. So, if this event hit a database, the database is called multiple times causing a lot of problems (poor performance application).

To solve it, i added a name for each event (keydown.typewatch, paste.typewatch ...), and you can unbind just this event to restart typewatch, like this code:

´´´´
$(document).ready(function () {
jsf.ajax.addOnEvent(restartTypewatch);
});

function restartTypewatch(){
//unbind all events to avoid multiple calls
$('#my-input-text').unbind('keydown.typewatch paste.typewatch cut.typewatch input.typewatch');

//start typeWatch again
$('#my-input-text').typeWatch(options);
}
´´´´

You can't unbind all "keydown" events because it will cause problems in another jquery-plugins, like this:

´´´´
//unbind all keydown in this component can cause problem in others plugins, better unbind just typewatch
$('#my-input-text').unbind('keydown');
´´´´
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant