﻿id	summary	reporter	owner	description	type	status	component	version	severity	resolution	keywords	cc	stage	has_patch	needs_docs	needs_tests	needs_better_patch	easy	ui_ux
19314	JavaScript for Widget in added inline	Per Rosengren	Per Rosengren	"A django.forms.widgets.Widget can add javascript in its render function. This can include state variables related to the widget.

This problem applies to widgets in inline forms. When an extra inline is added (using javascript in admin), a special hidden empty inline is cloned, setup and showed. The widget javascript was applied to the hidden inline, so any state is connected to that. 

What is needed is to not run the javascript for the empty inline's widget, and to trigger the javascript to run on any added (cloned) inline forms' widget. I suggest we modify django/contrib/admin/static/admin/js/inlines.js to trigger a custom event that contains the added DOM element. The widget code can then bind its activation function to that event, and apply it to the widget HTML within the event's element.

I can do the patch if you agree this is the way to solve it.

This is the widget javascript I currently use:
{{{
jQuery(document).ready(function ($) {
    $('.form-row:not(.empty-form) #id_{{ name }}').wymeditor({
    	basePath: '{% static ""js/wymeditor/"" %}',
        updateSelector: 'input[type=submit],',
        updateEvent: 'click',
        lang: '{{ language }}',
        skin: 'default',
		logoHtml: ''
    });
});
}}}

"	New feature	closed	contrib.admin	dev	Normal	duplicate	admin forms		Accepted	1	0	0	0	0	0
