Through to the end

This commit is contained in:
2018-11-25 13:48:52 +00:00
parent d87604c6bd
commit 9384b6c9cb
4 changed files with 246 additions and 224 deletions

View File

@ -40,8 +40,8 @@
<!-- Conditional logic for hiding and un-hiding fields. -->
<script>
function showIf(thingToShow, whetherToShowIt) {
if (whetherToShowIt) {
function showIf(thingToShow, shouldShow) {
if (shouldShow) {
$(thingToShow).show()
} else {
$(thingToShow).hide()
@ -76,15 +76,10 @@
"showHide": ["#mineral_commodity_questions"],
"condition": ["SM"]
},
{ // 3.1
"field": "#id_positive_or_negative",
"showHide": ["#positive_case_questions"],
"condition": ["P"]
},
{ // 3.2
"field": "#id_positive_or_negative",
"showHide": ["#negative_case_questions"],
"condition": ["N"]
"showHide": ["#div_id_obstacles_and_hindrances"],
"condition": ["P", "N"]
}];
// Here we define the checkboxes that we need to use to
@ -109,7 +104,7 @@
}
];
var conditionalRadioGroups = [
var conditionalControls = [
{
name: "power_technology",
redraw: function() {
@ -153,7 +148,46 @@
showIf(section, input.checked)
}
}
}
},
{
name: "sector_of_economy",
redraw: function() {
const sector = document.forms['case-study-form'].sector_of_economy
const input = document.querySelector(`[name=positive_case_type][value=CORS]`)
// If sector of economy is transmission, mining, or processing
// Then enable this input. Otherwise, disable.
input.disabled = ['PG', 'SM', 'MA'].includes(sector.value) ? false : true
}
},
{
name: "positive_or_negative",
redraw: function() {
const setting = document.forms['case-study-form'].positive_or_negative
const relatedElements = [
{ value: 'P', elements: '.organising-pro' },
{ value: 'N', elements: '.organising-vs' },
{ value: 'X', elements: '.organising-none' },
{ value: 'U', elements: '.organising-idk' },
{ value: '', elements: '.organising-idk' },
]
let show = null
for (const { value, elements } of relatedElements) {
if (value === setting.value) {
show = elements
}
$(elements).css("display", "")
}
$(show).css("display", "inline")
}
},
]
// Define a function that hides the field and then creates a listener to toggle the field.
@ -230,8 +264,8 @@
$(item.checkbox).change();
});
conditionalRadioGroups.forEach(function (group) {
$(`input[name=${group.name}]`).on('change', group.redraw)
conditionalControls.forEach(function (group) {
$(`[name=${group.name}]`).on('change', group.redraw)
group.redraw();
});
});