Through to row 101

This commit is contained in:
2018-11-24 17:58:08 +00:00
parent 5c4e9c330d
commit 857634d1f1
3 changed files with 148 additions and 90 deletions

View File

@ -48,11 +48,6 @@
"showHide": ["#div_id_type_of_ecosystem"],
"condition": ["RUR"]
},
{
"field": "#id_power_technology",
"showHide": ["#div_id_power_technology_other"],
"condition": ["OT"]
},
{ // 2.1 - Power Generation
"field": "#id_sector_of_economy",
"showHide": ["#power_generation_questions"],
@ -61,12 +56,7 @@
{
"field": "#id_generation_technology",
"showHide": ["#div_id_biomass_detail"],
"condition": ["BIOG", "OTHB"]
},
{
"field": "#id_generation_technology",
"showHide": ["#div_id_generation_technology_other"],
"condition": ["OTHR"]
"condition": ["BIO"]
},
{ // 2.2 - Power Grids
"field": "#id_sector_of_economy",
@ -94,19 +84,66 @@
// logic as they rely on the 'checked' attribute rather than value.
var conditionalCheckboxes = [
{
"checkbox": "#id_affects_indigenous",
"showHide": "#div_id_affects_indigenous_detail"
checkbox: "#id_affects_indigenous",
showHide: "#div_id_affects_indigenous_detail",
},
{
"checkbox": "#id_shown_on_other_platforms",
"showHide": "#div_id_shown_on_other_platforms_detail"
checkbox: "#id_shown_on_other_platforms",
showHide: "#div_id_shown_on_other_platforms_detail"
},
{
"checkbox": "#id_negative_case_reasons_8",
"showHide": "#div_id_negative_case_reasons_other"
}
checkbox: "#id_negative_case_reasons_8",
showHide: "#div_id_negative_case_reasons_other"
},
];
var conditionalRadioGroups = [
{
name: "power_technology",
redraw: function() {
const other = document.getElementById('id_id_power_technology_0_4')
const showHide = document.getElementById('div_id_power_technology_other')
if (other.checked) {
$(showHide).show();
} else {
$(showHide).hide();
}
}
},
{
name: "sector_of_economy",
redraw: function() {
var sections = [
{
"input": "id_id_sector_of_economy_0_1",
"section": "power_generation_questions",
},
{
"input": "id_id_sector_of_economy_0_2",
"section": "power_grids_energy_storage_questions",
},
{
"input": "id_id_sector_of_economy_0_3",
"section": "mineral_commodity_questions",
},
]
for (const option of sections) {
const input = document.getElementById(option.input)
const section = document.getElementById(option.section)
if (input.checked) {
$(section).show();
} else {
$(section).hide();
}
}
}
}
]
// Define a function that hides the field and then creates a listener to toggle the field.
// Takes a single conditionalField dictionary with (field, showHide and condition).
function addConditionalField(item) {
@ -137,34 +174,6 @@
});
}
var analysisToggles = [
{
"input": "id_id_sector_of_economy_0_1",
"section": "power_generation_questions",
},
{
"input": "id_id_sector_of_economy_0_2",
"section": "power_grids_energy_storage_questions",
},
{
"input": "id_id_sector_of_economy_0_3",
"section": "mineral_commodity_questions",
},
]
function showAnalysisSection() {
for (const option of analysisToggles) {
const input = document.getElementById(option.input)
const section = document.getElementById(option.section)
if (input.checked) {
$(section).show();
} else {
$(section).hide();
}
}
}
// Helper functions
function show(tag) {
$(tag).show();
@ -209,12 +218,10 @@
$(item.checkbox).change();
});
for (const option of analysisToggles) {
const input = document.getElementById(option.input)
$(input).on('change', showAnalysisSection);
$(input).trigger('change');
}
conditionalRadioGroups.forEach(function (group) {
$(`input[name=${group.name}]`).on('change', group.redraw)
group.redraw();
});
});
</script>