$(document).ready(function() {
    var search_field = $('#id_livesearch');
    var search_key = search_field.attr('data-key');
    var label = search_field.attr('data-label');
    if (!label) {
        label = 'name';
    }

    search_field.autocomplete({
        source: function(request, response) {
            $.ajax({
                type: 'GET',
                url: search_field.attr('data-source'),
                data: search_key + '=' + request.term,
                success: function(data) {
                    var choices = [];
                    $.each(data, function (index, choice) {
                        choices.push({
                            value: choice.id,
                            label: choice[label]
                        });
                    });
                    response(choices);
                }
            });
        },
        select: function(event, ui) {
            event.preventDefault();
            search_field.val(ui.item.label);
            var real_field = $('#id_' + search_field.attr('data-field'));
            real_field.empty();
            real_field.append($("<option></option>").attr('value', ui.item.value).text(ui.item.label));
            real_field.change();
            // If the field has a parent helper, reset the parent to no selection
            $('select[filter-for="' + real_field.attr('name') + '"]').val('');
        },
        minLength: 4,
        delay: 500
    });
});

@@ -64,24 +64,90 @@
 vesearch');%0A
+    var real_field = $('#id_' + search_field.attr('data-field'));%0A
     var sear
@@ -284,16 +284,256 @@
 %0A    %7D%0A%0A
+    // Update livesearch text when real field changes%0A    search_field.val(real_field.children('option:selected').text());%0A    real_field.change(function() %7B%0A        search_field.val(real_field.children('option:selected').text());%0A    %7D);%0A%0A
     sear
@@ -1295,82 +1295,8 @@
 l);%0A
-            var real_field = $('#id_' + search_field.attr('data-field'));%0A
     

Update livesearch text when real field changes