Results 1 to 4 of 4

Thread: How to prevent paste into textfield

  1. #1
    Sencha Premium User
    Join Date
    Dec 2010
    Posts
    288
    Answers
    8

    Default Answered: How to prevent paste into textfield

    I have a requirement where a certain form field cannot have values pasted into it. I can detect the when ctrl + v is pressed but how do I stop a value from being pasted?

    I tried

    Code:
        onAmountFieldKeydown: function(textfield, e, eOpts) {
            if (e.getKey() == 86 && e.ctrlKey) {
                e.stopEvent();
            }
        }
    This does detect ctrl + v but e.stopEvent(); does not stop the values from being pasted.


  2. #2
    Sencha User
    Join Date
    Feb 2017
    Posts
    15
    Answers
    3

  3. #3
    Sencha Premium User
    Join Date
    Dec 2010
    Posts
    288
    Answers
    8

    Default

    enableKeyEvents was set but for some reason this works on my computer at work but on my computer at home it does not. Very strange.

    My computer at work uses a very old ps2 type keyboard and my computer at home uses a newer gaming usb keyboard. Wonder if that would make a difference. Anyway, thanks for the help!

  4. #4
    Sencha MVP Team Member
    Join Date
    Sep 2016
    Location
    Kennewick, WA
    Posts
    153
    Answers
    15

    Default

    Here is a fiddle where I trap the ctrl key and then use e.preventDefault().


Similar Threads

  1. Cannot paste with Control V in TextField
    By shiraz.iskenderian in forum Ext GWT: Q&A
    Replies: 1
    Last Post: 28 Oct 2012, 4:33 PM
  2. Replies: 5
    Last Post: 14 May 2012, 4:57 AM
  3. How to disable copy\paste in TextField?
    By nosferatum in forum Ext 3.x: Help & Discussion
    Replies: 1
    Last Post: 22 Oct 2010, 5:24 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •