1 // setup ajax based autocomplete for the school field in the add course lightbox
4 // Dismiss on exit x click
5 $(".lightbox_close").click(function() {
6 $(".modal_content").hide();
10 // Assumes variable csrf_token is made available
11 // by embedding document
13 beforeSend: function(xhr, settings) {
14 if (!(/^http:.*/.test(settings.url) || /^https:.*/.test(settings.url))) {
15 // Only send the token to relative URLs i.e. locally.
16 xhr.setRequestHeader("X-CSRFToken", '{{ csrf_token }}');
24 $("#str_school").autocomplete({
25 source: function(request, response){
27 url: "{% url 'json_school_list' %}",
28 data: {q: request.term},
29 success: function(data) {
31 if (data['status'] === 'success') {
32 response($.map(data['schools'], function(item) {
40 // FIXME: do something if school not found
41 $('#create_school_link').show();
48 select: function(event, ui) {
49 console.log("select func");
51 console.log(ui.item.value);
53 console.log(ui.item.label);
54 // set the school id as the value of the hidden field
55 $('#id_school').val(ui.item.real_value);
56 // set the School name as the textbox field
57 //$('#str_school').val(ui.item.label);