141
Views
5
Comments
Solved
How do I prevent someone from pasting in a textbox?
Question

Hi there,


I would like to disable the paste function on a textbox, as far as I can I have no idea how to do this, please assist.


Thanks

2022-07-07 18-45-50
Niels Favreau
Solution

Hi Tjaart, 


You will find an OML in attach. You will see how it's done. (avoiding the right click paste funtion aswel)

Quick recap :

- Create an expression with escape content to 'no'. (drag it wherever you want)

- In the expression, you will have to write <script type="javascript"....

- In the script, call the document.ready function. 

- Reference your textbox runtime id. (this will be translated automaticly to the html id of the element)

- Disable the paste function


Greetings,

Niels

DisabledPasteTextBox.oml
2020-09-15 13-07-23
Kilian Hekhuis
 
MVP

Tjaart,

You can easily google to get some JavaScript samples of how to achieve this. Not though that it's very bad usability and your users will hate you.

2022-07-07 18-45-50
Niels Favreau
 $('yourtextboxRuntimeid').bind("cut copy paste",function(e) {
     e.preventDefault();
 });
2017-12-01 10-04-32
Tjaart Swanepoel

Niels Favreau wrote:

 $('yourtextboxRuntimeid').bind("cut copy paste",function(e) {
     e.preventDefault();
 });

Thanks for this, but as a total newbie, how would I apply the code to a Textarea?


2022-07-07 18-45-50
Niels Favreau
Solution

Hi Tjaart, 


You will find an OML in attach. You will see how it's done. (avoiding the right click paste funtion aswel)

Quick recap :

- Create an expression with escape content to 'no'. (drag it wherever you want)

- In the expression, you will have to write <script type="javascript"....

- In the script, call the document.ready function. 

- Reference your textbox runtime id. (this will be translated automaticly to the html id of the element)

- Disable the paste function


Greetings,

Niels

DisabledPasteTextBox.oml
2017-12-01 10-04-32
Tjaart Swanepoel

Thanks

Community GuidelinesBe kind and respectful, give credit to the original source of content, and search for duplicates before posting.