Block Copy Paste in a text entry box | XM Community
Skip to main content
Solved

Block Copy Paste in a text entry box


Forum|alt.badge.img+1

I have two text entry boxes on a survey that are meant for employee ID. Both have custom validation. The first one limits entry to a specific number of numeric digits only. The second one serves to match against the first one.

I would like to prevent someone from copying the value from the first one (in case it is incorrect) and pasting it into the second one.

Best answer by rondev

Try the below code:
jQuery("#"+this.questionId+" .InputText:eq(0)").on("cut copy paste",function(e) {
   e.preventDefault();
  });

View original

8 replies

rondev
Level 6 ●●●●●●
Forum|alt.badge.img+22
  • Level 6 ●●●●●●
  • 1449 replies
  • May 12, 2020

For this I guess you are using text entry form type question with two fields.
Paste the below code in the JS of this question:
jQuery("#"+this.questionId+" .InputText:eq(1)").on("cut copy paste",function(e) {
   e.preventDefault();
  });


Forum|alt.badge.img+1

Thanks. I must be doing something wrong. I know nothing about Java Script. This is what I see when I go to the JS portion for the field. Do I replace the entire thing with your line of code? Or?

Qualtrics.SurveyEngine.addOnload(function()
{
 /*Place your JavaScript here to run when the page loads*/
});
Qualtrics.SurveyEngine.addOnReady(function()
{
 /*Place your JavaScript here to run when the page is fully displayed*/
});
Qualtrics.SurveyEngine.addOnUnload(function()
{
 /*Place your JavaScript here to run when the page is unloaded*/
});


rondev
Level 6 ●●●●●●
Forum|alt.badge.img+22
  • Level 6 ●●●●●●
  • 1449 replies
  • May 12, 2020

It will be under onReady function as shown below:
image.png


Forum|alt.badge.img+1

This is what I have. Upon testing in preview mode and through a link, I can still copy/paste. I tried putting it in the JS for each of the two questions thinking that might work, but it didn't.


2020-05-14_20-05-03.png


rondev
Level 6 ●●●●●●
Forum|alt.badge.img+22
  • Level 6 ●●●●●●
  • 1449 replies
  • May 15, 2020

Which question type are you using?


Forum|alt.badge.img+1


The custom validation is Matches RegEx to make it so that the user can only enter seven numerical digits.
2020-05-15_6-11-05.png


rondev
Level 6 ●●●●●●
Forum|alt.badge.img+22
  • Level 6 ●●●●●●
  • 1449 replies
  • Answer
  • May 15, 2020

Try the below code:
jQuery("#"+this.questionId+" .InputText:eq(0)").on("cut copy paste",function(e) {
   e.preventDefault();
  });


Forum|alt.badge.img+1

Works perfectly. Thanks


Leave a Reply