Untitled
unknown
plain_text
a year ago
2.1 kB
1
Indexable
Never
function resetForm() { // Clear inputs and textarea $('input').val(''); $('textarea').val(''); $('#unit-label2').text(''); $('#charCount').text('0/250'); unitInput2.hide(); unitInput.removeClass('col-4').addClass('col-12'); $('.invalid-input').removeClass('invalid-input'); unitInput.prop('disabled', true); // Reset category and source select elements categorySelect.empty().append(new Option("Välj kategori", "", true, true)).prop('disabled', true); sourceSelect.empty().append(new Option("Välj källa", "", true, true)).prop('disabled', true); // Uncheck all the radio buttons scopeRadios.prop('checked', false); } $(document).ready(function () { // ... // Trigger change event on the first scope radio button to initialize categories // scopeRadios.first().prop('checked', true).trigger('change'); }); function onScopeChange() { let selectedScope = parseInt($(this).val(), 10); let categories = [...new Set(data.filter(item => parseInt(item.scope, 10) === selectedScope).map(item => item.category))]; // Clear the categories dropdown categorySelect.empty(); categorySelect.append(new Option("Välj kategori", "", true, true)); // Populate the categories dropdown categories.forEach(category => { categorySelect.append(new Option(category, category)); }); // Enable the categories dropdown categorySelect.prop('disabled', false); } function onCategoryChange() { if($(this).val() !== "") { sourceSelect.empty(); sourceSelect.append(new Option("Välj källa", "", true, true)).prop('disabled', false); let selectedScope = parseInt($('input[name="scope"]:checked').val(), 10); let selectedCategory = $(this).val(); let sources = [...new Set(data.filter(item => parseInt(item.scope, 10) === selectedScope && item.category === selectedCategory).map(item => item.source))]; sources.forEach(source => { sourceSelect.append(new Option(source, source)); }); } }