Are you maybe loading jQuery twice? Maybe you're loading it again after
jQuery UI? I suspect that this is what you're referring to when you say
"autocomplete light"...

In any case, I have used jQuery UI inside admin before inside order
creation in admin for looking up product items and it has worked for me.

Here's some code:

I've added the following Media files to OrderAdmin:

class OrderAdmin(admin.ModelAdmin):

    class Media:
        css = {"all": ("cartridge/css/admin/jquery-ui.min.css",)}
        js = ("cartridge/js/admin/jquery-ui.min.js",
"cartridge/js/admin/product_name_autocomplete.js")

The "cartridge/js/admin/product_name_autocomplete.js" has this code in it:

jQuery(document).ready(function () {
    jQuery(".description input").autocomplete({
        source: "/shop/product-name-autocomplete/",
        minLength: 2,
        select: function (event, ui) {}
    });

    jQuery(".description input").on("autocompleteselect", function (event,
ui) {
        var field_digit = jQuery(this).attr("id").split("-")[1];

jQuery('#id_items-'+field_digit+'-unit_price').val(ui.item.unit_price);

jQuery('#id_items-'+field_digit+'-total_price').val(ui.item.unit_price);
        jQuery('#id_items-'+field_digit+'-sku').val(ui.item.sku);
        jQuery('#id_items-'+field_digit+'-quantity').val(1);
    });
});


And the product lookup view is a simple one:

def product_name_autocomplete(request):
    if request.is_ajax():
        q = request.GET.get('term', '')
        products = Product.objects.filter(Q(title__icontains=q) |
Q(sku__icontains=q))[:20]
        results = []
        for p in products:
            product_json = {}
            product_json['sku'] = p.sku
            product_json['label'] = p.title
            product_json['unit_price'] = "%.2f" % p.unit_price
            results.append(product_json)
        data = json.dumps(results)
    else:
        data = 'fail'
    mimetype = 'application/json'
    return HttpResponse(data, mimetype)


The jQuery UI files are from https://jqueryui.com/. But I think that mezza
comes with this lib already.

I hope that helps!

Cheers,

M

On Tue, Sep 8, 2015 at 10:13 PM, Kbyte <[email protected]> wrote:

> I'm using often autocomplete light in my projects and I'm trying to use it
> with mezzanine.
>
> First at all, I've noticed that the jquery loading broke the admin panel:
> you can't execute any action to selected rows, the event simple wasn't
> fired. No javascript errors or logs.
>
> Just add this line to your admin/base_site.html
>
> <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.9.0/jquery.js"; 
> type="text/javascript"></script>
>
> On inlines elements, autocomplete override the "add new" on bottom, but it
> is broken because of the override made from mezzanine.
>
> This third-part app works fine in grappelli, could you try to make it
> usable in mezzanine?
>
> --
> You received this message because you are subscribed to the Google Groups
> "Mezzanine Users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to [email protected].
> For more options, visit https://groups.google.com/d/optout.
>

-- 
You received this message because you are subscribed to the Google Groups 
"Mezzanine Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/d/optout.

Reply via email to