1 // setup ajax based autocomplete for the school field in the add course lightbox
5 // Assumes variable csrf_token is made available
6 // by embedding document
8 beforeSend: function(xhr, settings) {
9 if (!(/^http:.*/.test(settings.url) || /^https:.*/.test(settings.url))) {
10 // Only send the token to relative URLs i.e. locally.
11 xhr.setRequestHeader("X-CSRFToken", '{{ csrf_token }}');
19 $("#str_school").autocomplete({
20 source: function(request, response){
22 url: "{% url 'json_school_list' %}",
23 data: {q: request.term},
24 success: function(data) {
26 if (data['status'] === 'success') {
27 response($.map(data['schools'], function(item) {
35 // FIXME: do something if school not found
36 $('#create_school_link').show();
43 select: function(event, ui) {
44 console.log("select func");
46 console.log(ui.item.value);
48 console.log(ui.item.label);
49 // set the school id as the value of the hidden field
50 $('#id_school').val(ui.item.real_value);
51 // set the School name as the textbox field
52 //$('#str_school').val(ui.item.label);