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):
- 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: