function setProgrammeChoice() {
    const programmeOptionsSelector = $('#id_degree_programme_options option');
    const programmeOptions = Object.values(programmeOptionsSelector).map(option => option.value);

    const currentProgramme = $('#id_degree_programme').val();
    if (programmeOptions.indexOf(currentProgramme) !== -1) {
        $('#id_degree_programme_options').val(currentProgramme);
    } else {
        $('#id_degree_programme_options').val('extra');
        $('#unknown_degree').show();
    }
}

$(document).ready(function() {

    // Set degree choice based on pre-existing data
    setProgrammeChoice();

    $('#id_degree_programme_options').change(function() {
        if (this.value === 'extra') {
            $('#unknown_degree').show();
            $('#id_degree_programme').val('');
        } else {
            $('#unknown_degree').hide();
            $('#id_degree_programme').val(this.value);
        }
    });

    $('#deleteapplicant').click(function() {
        if (confirm('Vill du radera denna ansökan?')) {
            const id = $(this).data('id');
			const request = $.ajax({
                url: '/api/applicants/' + id + '/',
                method: 'DELETE',
                data: {'applicant_id': id},
            });

            request.done(function() {
                window.location = '/admin/applicants/';
            });

            request.fail(function(jqHXR, textStatus) {
                alert('Request failed: ' + textStatus + ': ' + jqHXR.responseText);
            });
        }
    });

    $('#makemember').submit(function(event) {
        const id = $(this).data('id');
        const data = $(this).serialize();
        const request = $.ajax({
            url: '/api/applicants/makeMember/' + id + '/',
            method: 'POST',
            data: data,
        });

        request.done(function() {
            window.location = '/admin/applicants/';
        });

        request.fail(function(jqHXR, textStatus) {
            alert('Request failed: ' + textStatus + ': ' + jqHXR.responseText);
        });

        event.preventDefault();
    });
});

@@ -1,16 +1,647 @@
+/* Some browsers (e.g. desktop Safari) does not have built-in datepickers (e.g. Firefox).%0A * Thus we check first if the browser supports this, in case not we inject jQuery UI into the DOM.%0A * This enables a jQuery datepicker.%0A */%0A%0Avar datefield = document.createElement('input');%0Adatefield.setAttribute('type', 'date');%0A%0Aif (datefield.type != 'date') %7B%0A    const jQueryUIurl = 'http://ajax.googleapis.com/ajax/libs/jqueryui/1.12.1';%0A    document.write(%60%3Clink href=%22$%7BjQueryUIurl%7D/themes/base/jquery-ui.css%22 rel=%22stylesheet%22 type=%22text/css%22 /%3E%5Cn%60)%0A    document.write(%60%3Cscript src=%22$%7BjQueryUIurl%7D/jquery-ui.min.js%22%3E%3C%5C/script%3E%5Cn%60)%0A%7D%0A%0A
 function setProg
@@ -2734,13 +2734,356 @@
 %0A    %7D);
+%0A%0A    // Set the datepicker on birth date, in case input type of date is not supported%0A    if (datefield.type != 'date') %7B%0A        const currentYear = new Date().getFullYear();%0A%0A        $('#id_birth_date').datepicker(%7B%0A            changeMonth: true,%0A            changeYear: true,%0A            yearRange: %601930:$%7BcurrentYear%7D%60,%0A        %7D);%0A    %7D
 %0A%7D);%0A

Add datepicker support to admin site too