remove auto delete while deleting prefilled zeroes in constant sum | XM Community
Solved

remove auto delete while deleting prefilled zeroes in constant sum


Hi all, I have a constant sum matrix type where each box needs to have a number between 0 and 100. Additionally, I want to remove the prefilled zeroes and have blank spaces instead. 
I use the following code to remove the prefilled zeroes
Qualtrics.SurveyEngine.addOnload(function(){
jQuery("#"+this.questionId+ "td input[type=text]").val("");

});
and I use custom validation with "greater than or equal to 0" and "less than or equal to 100" in each box.
The problem is that if only one of the many boxes does not satisfy the condition, ALL the boxes become blank, so you need to start again.
Is there a way, in which you get the error message and you are not allowed to pass to the next question, BUT none of the answers, or only the answers that do not satisfy the condition, are deleted?
Thanks!

icon

Best answer by TomG 11 May 2020, 14:30

View original

17 replies

Userlevel 7
Badge +27

In your addOnload function you need to check to make sure the values are zero before changing them to blank.

Hi Tom, I am using this code now, but it allows to pass the question even if all the boxes are filled with zeroes. Do I need to add anything else to this code?

Qualtrics.SurveyEngine.addOnload(function() {
  var inputs = jQuery("#"+this.questionId+" .SumInput input");
  if(inputs.filter(function() {return this.value != "0";}).length == 0) {
  inputs.val("");
  }
});

Thanks!

Userlevel 7
Badge +27

Ali5 said:

Hi Tom, I am using this code now, but it allows to pass the question even if all the boxes are filled with zeroes. Do I need to add anything else to this code?

You don't need to change the code. You need to add a condition to your Custom Validation because as it is now all zeros is valid.

True, thank you!

Badge +2

https://community.qualtrics.com/XMcommunity/discussion/comment/25123#Comment_25123TomG Hi Tom, i am also using this code (see code above). If one validation is not correct, all the answers are blank (reload page). But i need blank spaces at the beginnig. Participants can enter zeros, that's not a problem. But after the reload they have to fill all spaces again. Can you help me? Thank you.

Userlevel 7
Badge +27

https://community.qualtrics.com/XMcommunity/discussion/comment/49863#Comment_49863Are you using the code above from Ali5? Is the Total option of your constant sum turned on?

Badge +2

https://community.qualtrics.com/XMcommunity/discussion/comment/49864#Comment_49864Yes, exactly and the constant sum is turned off. So the participants can enter values from 0 to 100. So there are 10 statement and you have to enter these values. You know what I mean?

Badge +2

TomG And i have a condition (there must be no blank boxes). And if only one of the many boxes does not satisfy the condition (e.g. empty box), ALL the boxes become blank, so you need to start again. How can I fix this issue? Thank you in advance

Userlevel 7
Badge +27

https://community.qualtrics.com/XMcommunity/discussion/comment/49867#Comment_49867The issue is the html structure is different for total vs no total. Here is a modification to Ali5's code that should work with either:
Qualtrics.SurveyEngine.addOnload(function() {
var q = jQuery("#"+this.questionId);
var inputs = q.find(".SumInput>.InputText,.SumInput.InputText");
  if(inputs.filter(function() {return this.value != "0";}).length == 0) {
  inputs.val("");
  }
});

Badge +2

https://community.qualtrics.com/XMcommunity/discussion/comment/49869#Comment_49869TomG Thank you so much for your help but at the beginning there zeros in the spaces.
grafik.png

Badge +2

https://community.qualtrics.com/XMcommunity/discussion/comment/49897#Comment_49897TomG but if there is false condition and there is a reload, the code is working 🙂 But is there any possibility that there are no pre filled zeros at the beginning? Thank you so much

Userlevel 7
Badge +27

MaGr,
It doesn't work because that isn't a constant sum question. It looks like a constant sum matrix with one scale point. Change the selector in

q.find()
.

Badge +2

https://community.qualtrics.com/XMcommunity/discussion/comment/49900#Comment_49900TomG Thank you, Tom. You are absolutely right. It's a constant sum matrix with one scale point and without a total. But unfortunately the code is still not working. You mean a code like this?
grafik.png

Userlevel 7
Badge +27

No, I meant q.find("add appropriate selector here"). You can use your browser's inspect feature to determine what the selector should be.

Badge +2

https://community.qualtrics.com/XMcommunity/discussion/comment/49904#Comment_49904TomG Thank you so much for your help. I have absolutely no idea about selectors and programming. Do you think there is another solution for my problem?

Userlevel 7
Badge +27

I was trying to help you help yourself. Use "td input[type=text]".

Badge +2

https://community.qualtrics.com/XMcommunity/discussion/comment/49913#Comment_49913TomG I am so sorry. You are absolutely right, but i am so stressed because i have a project deadline and i am trying to construct the questionnaire. But now it works. Thank so much, you are a legend 🙂

Leave a Reply