remove auto delete while deleting prefilled zeroes in constant sum

Ali5Ali5 FlorenceCommunity Member Qubie ✭

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!

Answers

  • TomGTomG Raleigh, NCCommunity Member Wizard ✭✭✭✭✭

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

  • Ali5Ali5 FlorenceCommunity Member Qubie ✭

    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!

  • TomGTomG Raleigh, NCCommunity Member Wizard ✭✭✭✭✭

    @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.

  • Ali5Ali5 FlorenceCommunity Member Qubie ✭

    True, thank you!

Sign In to Comment