Prevent users from pasting text into text entry fields within a SIDE BY SIDE question format | XM Community
Skip to main content

I would like to prevent users from pasting text into text entry fields within a SIDE BY SIDE question format. So far, I haven't been able to find a solution that works.

We are currently using the following JavaScript code:

jQuery("#"+this.questionId+" .InputText:eq(0)").on("cut copy paste",function(e) {

   e.preventDefault();

  });

This code successfully prevents pasting when applied to text box questions. However, it does not seem to work when used in the SIDE BY SIDE question format.

Could you please let me know if there is a specific way to disable pasting in this type of question? Any advice or guidance would be greatly appreciated.

 

@Oreg.students Add this JavaScript to the question

Qualtrics.SurveyEngine.addOnload(function() {
let textInputs = this.getQuestionContainer().querySelectorAll('inputttype="text"]');

textInputs.forEach(input => {
input.addEventListener('paste', function(e) {
e.preventDefault();
});
});
});

Hope it helps


Thank you for your help and for taking the time to respond. I will try out your suggestion.


I tried implementing it, but unfortunately, it didn't work as expected. The code only prevents pasting in one of the text entry cells within the SIDE BY SIDE question, but it doesn't affect the other cells.

Ideally, I would like the code to prevent pasting in all the text entry cells within the SIDE BY SIDE question format. Do you have any other suggestions or alternative solutions that could address this issue?

Thank you again for your assistance!


@Oreg.students That shouldn't happened, because the code specifically applying rule to all of the element that have 'inputptype="text"]'

Can you show me what’s your question looks like and which box got affected and which doesn’t


Here is where the code change worked. As you can see, this is a standard text question. 

 

In the images attached below, you can see that this is a side-by-side question - only the top left box is affected by the code I wrote, while the code does not apply to the other boxes.

Thanks in advance for the help!

 

@Oreg.students Yes, it’s because your code only target the eq(0) AKA first box while mine is targeting every textboxes. Anyway, I’m changing your code because it seems like that the one working for you. Just remove eq(0) and you’re good

Qualtrics.SurveyEngine.addOnReady(function() {
jQuery("#" + this.questionId + " .InputText").on("cut copy paste", function(e) {
e.preventDefault();
});
});

 


Thank you!


Leave a Reply