function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Robert Wambold 10Robert Wambold 10 

Is it possible to prevent user from pasting data into a text field?

Hello all,

I have a request to prevent users from pasting data into a text field, is this even possible?

Thanks in advance for your help!

Robert

 

 

 

SwethaSwetha (Salesforce Developers) 
HI Robert,
Yes, this functionality is possible
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(); 
}

Reference: https://salesforce.stackexchange.com/questions/247097/how-to-add-a-functionality-to-stop-copy-paste-on-an-input-field-in-lightning

Related:https://stackoverflow.com/questions/15320069/how-to-prevent-user-pasting-text-in-a-textbox

Hope this helps you. Please mark this answer as best so that others facing the same issue will find this information useful. Thank you
Robert Wambold 10Robert Wambold 10

Hi Swetha,

Thanks for the link and code! I created the Code and Controller, but how to I get it work on Case object field?

Robert

 

 

SwethaSwetha (Salesforce Developers) 
Is it a standard field of case object or custom one?
Robert Wambold 10Robert Wambold 10

CustomField, Case.Client_Internal_Impact__c 

Type = TextArea