Welcome to the LimeSurvey Community Forum

Ask the community, share ideas, and connect with other LimeSurvey users!

Create Array 5 Point Choice with Random number, category and maximum score

More
5 years 5 months ago #194933 by Maverick87Shaka
Thanks for your feedback.
Yes, I was on latest 4.1.8 and now I've migrated on 3.22.7 LTS trying to solve the problem.
The Admin interface its really faster, and adding the 270 subquestions using quick add and other functions.....works really faster then before.
But I still have the issue when I try to execute the survey, when it's the time to make the rating of the subquestion, I have browser freeze if inside the question I put {sum(self.NAOK)} or in the validation.


Here the .lss with the 270 subquestions and total sum:

File Attachment:

File Name: limesurvey...Text.lss
File Size:216.89 KB
The topic has been locked.
More
5 years 5 months ago #194950 by tpartner
If you are simply trying to display a running count of the "points", instead of using Expression Manager, you can use normal JavaScript by adding something like this to the question text.

The question will still load slowly due to the large number of relevance equations but, once loaded, the radio buttons will respond correctly.

Code:
<p>Some question text...</p>
<p>You have spent <b><span class="points-count">0</span></b> points of 150 available</p>
<script type="text/javascript" charset="utf-8">
 
  $(document).on('ready pjax:scriptcomplete',function(){  
 
    var thisQuestion = $('#question{QID}');
 
    // Listener on the radio buttons
    $('input:radio', thisQuestion).on('click', function(e) {
      var points = 0;
      $('tr.answers-list:visible input:radio:checked', thisQuestion).each(function(i) {
        points = points + Number($(this).val());
      });
 
      $('span.points-count', thisQuestion).text(points);
    });
    });
</script>

Cheers,
Tony Partner

Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
The following user(s) said Thank You: Maverick87Shaka
The topic has been locked.
More
5 years 5 months ago - 5 years 5 months ago #194958 by Maverick87Shaka
Thanks tpartner!
This code works well without causing any lags while compiling, and makes the goal to display the actual scoring. There is a way to store it and use in the Validation Equation?
At the moment I have just found a quick way in javascript to prevent the users to go ahead, but it's not warning a user like a validation equation, so user can feel lost on why can't submit.
Code:
<script type="text/javascript" charset="utf-8">
 
  $(document).on('ready pjax:scriptcomplete',function(){  
 
    var thisQuestion = $('#question{QID}');
        var btSubmit = document.getElementById('ls-button-submit');
 
    // Listener on the radio buttons
    $('input:radio', thisQuestion).on('click', function(e) {
      var points = 0;
      $('tr.answers-list:visible input:radio:checked', thisQuestion).each(function(i) {
        points = points + Number($(this).val());
      });
 
      $('span.points-count', thisQuestion).text(points);
                        if (points > 50) {
                              btSubmit.disabled = true;
                        }
                        else {
                             btSubmit.disabled = false;
                        }
    });
    });
</script>
Last edit: 5 years 5 months ago by Maverick87Shaka. Reason: missing tags
The topic has been locked.
More
5 years 5 months ago - 5 years 5 months ago #194991 by tpartner
In that case, I would...

- Remove the validation from the array.

- Insert a numeric question directly after the array (for this example, with question code control1).

- Place a validation equation on that question like this (in this example I will use a maximum of 50 points):
Code:
control1 <= 50

- Place this HTML and script in the numeric question. It will hide the answer, populate the answer with a count from the array and display different text depending on that count. If the array total is over the max allowed the numeric question is invalid so you cannot proceed.
Code:
<p>{if(control1 <= 50, 'You may use up to 50 points', '<span class="text-danger">Warning, you must not exceed 50 points!</span>')}</p>
<script type="text/javascript" charset="utf-8">
 
  $(document).on('ready pjax:scriptcomplete',function(){  
 
    var thisQuestion = $('#question{QID}');
    var arrayQuestion = $(thisQuestion).prevAll('.question-container:eq(0)');
 
    // Listener on the radio buttons
    $('input:radio', arrayQuestion).on('click', function(e) {
      var points = 0;
      $('tr.answers-list:visible input:radio:checked', arrayQuestion).each(function(i) {
        points = points + Number($(this).val());
      });
 
      $('input:text', thisQuestion).val(points).trigger('change');
    });
 
    // Hide some elements
    $('.question-valid-container, .answer-container', thisQuestion).hide();
    });
</script>

Sample survey attached:

File Attachment:

File Name: limesurvey...3378.lss
File Size:230.41 KB





Cheers,
Tony Partner

Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
Last edit: 5 years 5 months ago by tpartner.
The topic has been locked.
Moderators: tpartnerholch

Lime-years ahead

Online-surveys for every purse and purpose