foerderbarometer/input/static/js/project-categories.js

32 lines
1.1 KiB
JavaScript

(function ($) {
$(function () {
$('#id_categories, #id_wikimedia_projects').each(function () {
const otherCheckbox = $(this).find('input[value=0]');
const otherInputSelector = '#'.concat(this.id, '_other');
const otherInput = $(otherInputSelector);
const otherLabelSelector = 'label'.concat('[for="', this.id, '_other"]');
const otherLabel = $(otherLabelSelector);
const otherTableRow = otherInput.parents('tr');
const toggle = function () {
const checked = otherCheckbox.prop('checked');
otherInput.prop('disabled', !checked);
otherInput.prop('required', checked);
otherLabel.toggleClass('required', checked);
otherTableRow.css('visibility', checked ? 'visible' : 'collapse');
if (checked) {
otherInput.focus();
} else {
otherInput.val('');
}
};
toggle();
otherCheckbox.on('change', toggle);
});
});
})(django.jQuery);