0

I have right now this function in my view, using Primefaces (6.2):

<p:inputText id="globalFilter" style="width:150px" onkeyup="PF('#{widgetVar}').filter()" placeholder="Searching..."/>

The filter function is fired right on the first keyup, so the user can't even enter 2-3 characters, which is bad.

How can I add some delay to it? As far as I saw there in no "delay" option on p:inputText, only on ajax events, but sadly I don't know how to rewrite it, to use this PF function AND ajax event...

Thank you for the help!

Jasper de Vries
  • 19,370
  • 6
  • 64
  • 102
VORiAND
  • 145
  • 3
  • 17
  • 35
  • This is Primefaces, not jQuery – VORiAND Mar 27 '19 at 10:35
  • PrimeFaces uses jQuery for its components. – Jasper de Vries Mar 27 '19 at 10:37
  • I know that, but this information is not helping me :( – VORiAND Mar 27 '19 at 10:46
  • 1
    Why not? The `onkeyup` attribute will take a JavaScript function (just as with plain HTML). You can do exactly the same as answered on the duplicate. – Jasper de Vries Mar 27 '19 at 10:49
  • Will this work with my PF('#{widgetVar}').filter() function as well? – VORiAND Mar 27 '19 at 10:50
  • 1
    https://www.google.com/search?q=Can+I+use+EL+in+JavaScript – Jasper de Vries Mar 27 '19 at 10:55
  • 1
    Try with `` and you have the same problem. Not even a JSF issue effectively. – Kukeltje Mar 27 '19 at 11:49
  • I don’t understand. What has to do this with Primafaces delay? – VORiAND Mar 27 '19 at 12:34
  • Nothing. But since your `onkeyup` is an attribute that is verbatim passed through to the plain html input on the client side, the actual question is not PrimeFaces related at all but a plain html/javascript one and you should solve it as such. This is what is done in the duplicate (with the help of jquery).. – Kukeltje Mar 27 '19 at 19:00
  • But if you actually wanted to use a PrimeFaces ajax solution, you should have provided an attempt or even better, tried some basic searching: https://www.google.com/search?q=primefaces+ajax+input+delay contains enough relevant info... – Kukeltje Mar 27 '19 at 19:04
  • 1
    And since I'm in a good mood: https://stackoverflow.com/questions/8401218/primefaces-keyup-event-delay – Kukeltje Mar 27 '19 at 20:02
  • 1
    This is the simple Primefaces answer: – VORiAND Mar 27 '19 at 21:15
  • @VORiAND I had the same question of how to do this in PrimeFaces, and your comment about using is the perfect solution. Could you make it into an answer as I wouldn't have seen it without expanding the comment section! – Ralph Oct 26 '21 at 09:50
  • Thank you, but thanks to the moderators, the question was marked as duplicate, so I can't answer it anymore :) – VORiAND Oct 27 '21 at 12:12

0 Answers0