Skip to content

Commit

Permalink
Surveys: Fix dependency with multiple children. BT#15488
Browse files Browse the repository at this point in the history
  • Loading branch information
jmontoyaa committed Aug 18, 2020
1 parent 62f646c commit 1aec20b
Showing 1 changed file with 10 additions and 14 deletions.
24 changes: 10 additions & 14 deletions main/survey/survey_question.php
Expand Up @@ -616,34 +616,26 @@ public static function getQuestionJs($question)
foreach ($list as $child) {
$childQuestionId = $child['question_id'];
$optionId = $child['parent_option_id'];
$newList[$optionId] = $childQuestionId;
$newList[$optionId][] = $childQuestionId;
}

if ('multipleresponse' === $type) {
$multiple = '';
foreach ($newList as $optionId => $child) {
$multiple .= '
$(\'input[name="question'.$questionId.'['.$optionId.']"]\').on("change", function() {
var isChecked= $(this).is(\':checked\');
var checkedValue = $(this).val();
if (isChecked) {
$.each(list, function(index, value) {
//$(".with_parent_" + value).hide();
$(".with_parent_" + value).find("input").prop("checked", false);
//$(".with_parent_only_hide_" + value).hide();
});
var questionId = $(this).val();
var questionToShow = list[questionId];
$(".with_parent_" + questionToShow).show();
} else {
var checkedValue = list[checkedValue];
//$.each(list, function(index, value) {
$(".with_parent_" + checkedValue).hide();
$(".with_parent_" + checkedValue).find("input").prop("checked", false);
$(".with_parent_only_hide_" + checkedValue).hide();
//});
}
});
';
Expand All @@ -666,14 +658,18 @@ public static function getQuestionJs($question)
var list = '.json_encode($newList).';
$("input[name=question'.$questionId.']").on("click", function() {
$.each(list, function(index, value) {
$(".with_parent_" + value).hide();
$(".with_parent_" + value).find("input").prop("checked", false);
$(".with_parent_only_hide_" + value).hide();
$.each(value, function(index, itemValue) {
$(".with_parent_" + itemValue).hide();
$(".with_parent_" + itemValue).find("input").prop("checked", false);
$(".with_parent_only_hide_" + itemValue).hide();
});
});
var questionId = $(this).val();
var questionToShow = list[questionId];
$(".with_parent_" + questionToShow).show();
var questionToShowList = list[questionId];
$.each(questionToShowList, function(index, value) {
$(".with_parent_" + value).show();
});
});
});
</script>';
Expand Down

0 comments on commit 1aec20b

Please sign in to comment.