1 Reply Latest reply on Jun 3, 2010 6:49 AM by mettehummel

    How to find out if text is pasted into an input field

    mettehummel

      I have an input field and I want to be able to do something in my backingBean whenever a user change the text in this field. So far I have added an onkeyup so I can do my stuff when a key is pressed, but what if the user uses the mouse to select, copy and paste a text into the input field?

       

      Is there a way to find out if a user choose to paste text into an input text ?

      Using onchange will do the trick, but only after the user leaves the field and that is to late for me.

        • 1. Re: How to find out if text is pasted into an input field
          mettehummel

          Figured out a way to solve the problem. Added the following code.

           

          function settOnpaste(element) {

                 if (element.nodeType == 1){   

                          element['onpaste'] = handlePasteEvents;

                  }

          }

          function handlePasteEvents(e, elName) {

                  radEndret(e);

          }

           

          <h:inputText id="inputBeskrivelse" value="#{linje.beskrivelse}"

                  onfocus="settOnpaste(this)">

          </h:inputText>