trouble with inline and jquery plugins in django

291 views Asked by At

Have troubles with inline in django admin. For example, i want to add a chosen jquery plugin to my Change_form page. I'm extends change_from html and add next code

{% extends "admin/change_form.html" %}

{% block extrahead %}
{{ block.super }}

<script src="{{ MEDIA_URL }}js/chosen.jquery.min.js"></script>
<link rel="stylesheet" href="{{ MEDIA_URL }}js/chosen.css" type="text/css" />
<style type="text/css">
.form-row {
    overflow: visible;
}
</style>
<script type="text/javascript">
$(function(){
    $("select").chosen();
});
</script>
{% endblock %}

All works perfectly, except "selects" in inline when i push "Add more". They work incorrectly. One gets the impression that the plugin works before widget creation, after clicking "Add more". Same trouble have with Redactor plugin

image Redactor error

1

There are 1 answers

0
Odif Yltsaeb On

1) you do not need to change the template to add your own plugin to admin page. Check this out. All you need to do is to add your media to your form and add your form to admin page - like it teaches in the page that speaks about django admin.

2) The issue you see is not django, but jquery/javascript issue. If new elements get added to the page then the new elements do not have the event bound to them. I havent used jquery for a while but there used to be "live" method for binding events to elements that get created on the run.

$('#element').live('eventname', callback(){});