From 9a3e38e1ed05c3d9dd8b9f2549df5467e50d2565 Mon Sep 17 00:00:00 2001
From: Benard Ebinu
Date: Fri, 22 Dec 2017 16:33:13 -0800
Subject: [PATCH] DIV-640: Only hide the fact sheet if none is selected
otherwise show it if any of the other check boxes are selected
* introduced the data-reveal_control_group data attribute which allows user to associate a group of checkbox items that should be treated as a single reveal group
---
edivorce/apps/core/static/js/functions.js | 21 ++++++++++++++-----
.../question/06_children_income_expenses.html | 8 +++----
2 files changed, 20 insertions(+), 9 deletions(-)
diff --git a/edivorce/apps/core/static/js/functions.js b/edivorce/apps/core/static/js/functions.js
index 81420af5..15adfe80 100644
--- a/edivorce/apps/core/static/js/functions.js
+++ b/edivorce/apps/core/static/js/functions.js
@@ -3,12 +3,16 @@
// data-target_id: id of information section
// data-reveal_target: reveal target_id section if true
// data-related_id: id of information section which needed to be hide when target_id section is shown or vice versa
+// data-reveal_control_group: the selector for checkbox items that all behave as one group. As long as one of them
+// is checked, the target_id or target_class will be shown. Otherwise
+// if they are all unchecked, the target_id will be hidden.
var reveal = function(el) {
var id = '#' + el.data("target_id");
var css_class = el.data("target_class");
var related_id = el.data("related_id");
var reveal_condition = el.data("reveal_condition");
var invert_target = el.data("invert_target");
+ var reveal_control_group = el.data("reveal_control_group");
var should_reveal = true;
@@ -54,7 +58,7 @@ var reveal = function(el) {
}
if (should_reveal) {
- showHideTargetId(el, id, related_id);
+ showHideTargetId(el, id, related_id, reveal_control_group);
showHideRevealClass(el, css_class);
if (el.prop('name') === "provide_certificate_later" || el.prop('name') === "original_marriage_certificate") {
@@ -69,20 +73,27 @@ var reveal = function(el) {
};
// hide or show based on target id
-var showHideTargetId = function(el, id, related_id) {
+var showHideTargetId = function(el, id, related_id, reveal_control_group) {
if (el.data("reveal_target") === true && el.prop('checked')) {
$(id).show();
- if (related_id !== undefined){
+ if (related_id !== undefined) {
$('#' + related_id).hide();
}
- if (id === "#has_children"){
+ if (id === "#has_children") {
reveal($("input[name=number_children_over_19]"));
}
// reveal nested question as well
- if (id ==="#marriage_certificate"){
+ if (id === "#marriage_certificate") {
reveal($("input[name=provide_certificate_later]:checked"));
}
+ } else if (reveal_control_group !== undefined) {
+ if ($(reveal_control_group).is(':checked').length === 0) {
+ $(id).hide();
+ if (related_id !== undefined){
+ $('#' + related_id).show();
+ }
+ }
} else {
$(id).hide();
if (related_id !== undefined){
diff --git a/edivorce/apps/core/templates/question/06_children_income_expenses.html b/edivorce/apps/core/templates/question/06_children_income_expenses.html
index 9ff7ed08..2f2c13be 100644
--- a/edivorce/apps/core/templates/question/06_children_income_expenses.html
+++ b/edivorce/apps/core/templates/question/06_children_income_expenses.html
@@ -874,12 +874,12 @@