0

I want to disable paste event on input box in Ant design. i didn't find a correct solution yet. Thanks in advance

i used this and worked

                    inputOriginclick = () => {
                   this.myOriginRef.current.input.onpaste = () => {
                    return false;
                  };
                    };
                    <Input
                        value={this.state.origin}
                        type='text'
                        placeholder='Enter City'
                        ref={this.myOriginRef}
                        onClick={this.inputOriginclick}
                        onChange={e => this.handleChage('origin', e)}
                      
                      />
Ajax S
  • 1
  • 2

3 Answers3

3

Check this solution found here How to prevent user pasting text in a textbox?

  <input
    name="somename"
    type="text"
    value=""
    required
    onCopy={false}
    onDrag={false}
    onDrop={false}
    onPaste={false}
    autocomplete="off"
/>
Chilarai
  • 1,842
  • 2
  • 15
  • 33
2

window.onload = function() {
 const noPaste = document.getElementById('nopaste');
 noPaste.onpaste = function(e) {
   e.preventDefault();
 }
}
<input type="text" value="" id="nopaste">

try this.

CodeBug
  • 1,649
  • 1
  • 8
  • 23
0

Prevent the default action by using preventDefault()

<Input
  type='text'
  onPaste={e=>{
    e.preventDefault();
    return false
  }}
/>

Use this props to block copy

onCopy={e=>{
  e.preventDefault();
  return false
}}

Thought will be helpful in the future. even though question asked long time back.

Sivaraj S
  • 340
  • 3
  • 14