Take, for example, this ModelAdmin:
class ExampleAdmin(admin.ModelAdmin):
prepopulated_fields = {
"slug": ("name",),
"full_slug": ("name", "category"),
}
It results in the following Javascript being generated in the template:
document.getElementById("id_full_slug").onchange = function() { this._changed = true; };
document.getElementById("id_name").onkeyup = function() {
var e = document.getElementById("id_full_slug");
if (!e._changed) { e.value = URLify(document.getElementById("id_name").value + ' ' + document.getElementById("id_category").value, 50); }
}
document.getElementById("id_category").onkeyup = function() {
var e = document.getElementById("id_full_slug");
if (!e._changed) { e.value = URLify(document.getElementById("id_name").value + ' ' + document.getElementById("id_category").value, 50); }
}
document.getElementById("id_slug").onchange = function() { this._changed = true; };
document.getElementById("id_name").onkeyup = function() {
var e = document.getElementById("id_slug");
if (!e._changed) { e.value = URLify(document.getElementById("id_name").value, 50); }
}
The cause of the problem is the event listeners being attached by simply setting the onkeyup property. This means the second assignment overwrites the first one.
To attach multiple event listeners, the addEvent function defined in core.js should be used.