4

I'm making a form that includes two fields, Email and Re-Enter Email. I don't want the user to copy and paste the email id in the second field. I have to prevent right clicks on the re-enter field and/or the pasting functionality in that field. How do I achieve this? We have onPaste for ui input fields but not for lightning.

  • 5
    Please don't do this. This is bad UX. It's bad enough if a field has to be entered twice. At least let your users paste content. – hsan Jan 18 at 13:59
  • 2
    "Please confirm this question by retyping it a second time without copy-pasting." Your users hate retyping as much as you do. – zovits Jan 18 at 14:57
  • 2
    Also note that people could still enter the email in the second field, and copy it to paste it in the first one – Rafalon Jan 18 at 15:20
  • I wouldn't even keep that field in my form if it was up to me. I fought against it. But that's what I've been 'instructed' to do. – vedant gupta Jan 21 at 6:28
10

You need to use HTML event attribute, example-

Component:

<lightning:input name="input1" label="Enter some text"  
    oncontextmenu="{! c.handleContext }" onpaste="{! c.handlePaste }"/>

Controller.js:

handlePaste: function(component, event, helper) {
    alert("yo");
    event.preventDefault(); 
},

handleContext: function(component, event, helper) {
    alert('test');
    event.preventDefault(); 
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.