Skip to content

Commit

Permalink
bugfix - Remove empty space from dropdown menu
Browse files Browse the repository at this point in the history
  • Loading branch information
taleksovska committed Feb 5, 2024
1 parent 1e8dad2 commit f581068
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 81 deletions.
97 changes: 21 additions & 76 deletions ckanext/scheming/templates/scheming/form_snippets/radio.html
Original file line number Diff line number Diff line change
Expand Up @@ -48,85 +48,30 @@


<script>

function disableDropdown(){
var dropdown = document.getElementById('field-type_of_dataset');
dropdown.disabled = true;

}

// function removeVersionField(){
// var txcVersionField = document.getElementById('field-txc_version');
// var transXChangeVersionElement = document.querySelector("#dataset-edit > div:nth-child(15)");
// var wholeField = document.querySelector("#dataset-edit > div:nth-child(16)");

// wholeField.style.display = 'none';
// txcVersionField.style.display = 'none';
// transXChangeVersionElement.style.display = 'none';
// }


function toggleFields() {
console.log("--------------")

// Set the display property to "none" for these 3 elements.
// We are getting them by selector which is not very feasable, but it is the only option for now.
var statusElement = document.querySelector("#dataset-edit > div:nth-child(14)");
var transXChangeVersionElement = document.querySelector("#dataset-edit > div:nth-child(16)");
var metadataValidationElement = document.querySelector("#dataset-edit > div:nth-child(17)");
var visibleToLAElement = document.querySelector("#dataset-edit > div:nth-child(19)");


var selectedOption = document.getElementById('field-type_of_dataset').value;
var statusField = document.getElementById('field-status');
var txcVersionField = document.getElementById('field-txc_version');
var metadataValidationField = document.getElementById('field-metadata_validation');
var visibleToLAField = document.querySelector("#dataset-edit > div:nth-child(19)");
if (selectedOption === 'txc_data') {
// No fields to hide for TransXChange Data
statusField.style.display = 'block';
txcVersionField.style.display = 'block';
metadataValidationField.style.display = 'block';
visibleToLAElement.style.display = 'block';


statusElement.style.display = 'block';
transXChangeVersionElement.style.display = 'block';
metadataValidationElement.style.display = 'block';
visibleToLAField.style.display = 'block';
var selectedOption = document.getElementById('field-type_of_dataset').value;

// Show all fields for the selected option
var fields = document.querySelectorAll(".form-group");
fields.forEach(function (field) {
field.style.display = 'block';
});

// Customize visibility based on the selected option
if (selectedOption === 'financial_data') {
// Hide specific fields for Financial Data
document.querySelector("#dataset-edit > div:nth-child(12)").style.display = 'none';
document.querySelector("#dataset-edit > div:nth-child(13)").style.display = 'none';
document.querySelector("#dataset-edit > div:nth-child(17)").style.display = 'none';
document.querySelector("#dataset-edit > div:nth-child(19)").style.display = 'none';
document.querySelector("#dataset-edit > div:nth-child(18)").style.display = 'none';


} else if (selectedOption === 'financial_data') {
// statusField.style.display = 'none';
txcVersionField.style.display = 'none';
metadataValidationField.style.display = 'none';
visibleToLAElement.style.display = 'none';



// statusElement.style.display = "none";
transXChangeVersionElement.style.display = "none";
metadataValidationElement.style.display = "none";
visibleToLAField.style.display = 'none';
}

}

}

function dataRender(){
var selectedOption = document.getElementById('field-type_of_dataset').value;

if(selectedOption === null || selectedOption === ''){
document.getElementById('field-type_of_dataset').addEventListener('change', toggleFields);
//removeVersionField();
toggleFields();
}
else {
disableDropdown();
//removeVersionField();
}
}

dataRender();

</script>
toggleFields();

document.getElementById('field-type_of_dataset').addEventListener('change', toggleFields);
</script>
12 changes: 7 additions & 5 deletions ckanext/scheming/templates/scheming/form_snippets/select.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,15 @@
{%- set form_restrict_choices_to=field.get('form_restrict_choices_to') -%}
{%- if not h.scheming_field_required(field) or
field.get('form_include_blank_choice', false) -%}
{%- do options.append({'value': '', 'text': ''}) -%}
{# Do not append empty option if not required or include blank choice #}
{%- endif -%}
{%- for c in h.scheming_field_choices(field) -%}
{%- if not form_restrict_choices_to or c.value in form_restrict_choices_to -%}
{%- do options.append({
'value': c.value|string,
'text': h.scheming_language_text(c.label) }) -%}
{%- if c.value != '' -%}
{%- do options.append({
'value': c.value|string,
'text': h.scheming_language_text(c.label) }) -%}
{%- endif -%}
{%- endif -%}
{%- endfor -%}
{%- if field.get('sorted_choices') -%}
Expand All @@ -35,4 +37,4 @@
)
%}
{%- snippet 'scheming/form_snippets/help_text.html', field=field -%}
{% endcall %}
{% endcall %}
11 changes: 11 additions & 0 deletions ckanext/scheming/templates/scheming/form_snippets/text.html
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,14 @@
%}
{%- snippet 'scheming/form_snippets/help_text.html', field=field -%}
{% endcall %}

<script>
function disableFileId() {
var file_id = document.getElementById('field-id');
if (file_id !== null && file_id.value !== '') {
file_id.disabled = true;
}
}

disableFileId();
</script>

0 comments on commit f581068

Please sign in to comment.