2

I'm making a filter tool using .keyup()

To make it look a bit nicer, I have the table fadeOut before the non-matching rows are hidden and then fadeIn once it's done.

$('tbody').animate({
    opacity: 0
}, 300,function(){
        $('tbody tr').addClass('filter_hide');
        $('tbody tr td.'+f+':icontains("'+v+'")').parents('tr').removeClass('filter_hide');

    $('.entry_total').text(count);
    setTimeout(function(){
        changeShow(1);
    }, 400)

});

note: :icontains is just a case-insensitive version of :contains. v is the val() of the changed input. changeShow() updates my pagination with the new results only, and brings the table visible again

It all works great except one thing: the code is triggered when I press shift, caps, tab and so on, so the table fades out and fades back in again for these key presses, which looks bad.

How can I exclude these 'non-printing' key presses from firing the function?

TH1981
  • 3,105
  • 7
  • 42
  • 78
  • 2
    You can't prevent the event from firing on certain keys, you can however check that the keyCode is a printable character prior to taking any action on it. See this Q: http://stackoverflow.com/questions/12467240/determine-if-javascript-e-keycode-is-a-printable-non-control-character – Rob M. Apr 15 '14 at 20:32
  • Where is your keyup code? – Jay Blanchard Apr 15 '14 at 20:32
  • @JayBlanchard - I've only copied some of the code as i've got some complicated crap going on around it so it's pulled out. – TH1981 Apr 15 '14 at 20:58
  • thanks @RobM. That's answered my question. if you add an answer, i'll mark it as a solution to close this out :) – TH1981 Apr 15 '14 at 20:59

0 Answers0