HackAssistant/registration

View on GitHub
applications/static/js/form_modifiers.js

Summary

Maintainability
B
5 hrs
Test Coverage
function make_field_typeahead(field_id, path_to_json) {
    $.ajax({
        type: "GET",
        url: path_to_json,
        dataType: "json"
    }).done(function (res) {
        $("#id_" + field_id).typeahead({source: res});
    }).fail(function (jqXHR, textStatus, errorThrown) {
        console.error("AJAX call failed: " + textStatus + ", " + errorThrown);
    });
}


function conditional_field(field_to_hide, field_to_track, f_eval_to_show) {
    var parent = field_to_hide.parent('div');
    field_to_track.on('change', function () {
        if (f_eval_to_show()) {
            parent.fadeIn();
        } else {
            parent.fadeOut();
            field_to_hide.val('');
        }
    });
    if (!f_eval_to_show()) {
        parent.hide()
    }


}