Hi, django users.
I have found possible bug in django admin site, using tabular inline with datetime field. The same bug exists in stacked inline as I can see form code.
I am not sure what is the best way to report the bug, so I decided to write here first.
Please, give me advice on my next steps.
Now, about the bug.
Any datetime field is supplied with calendar and clock shortcuts. static/admin/js/admin/DateTimeShortcuts.js contains code, wich generated all html markup for them, this code runs on page load event.
This code makes both span class="datetimeshortcuts" and hidden div class="calendarbox module" or class="clockbox module".
TabularFormset and stackedFormset jquery plugins, that live in static/admin/js/inlines.js, both need to reinit datetime fields in the newly added formset rows.
They do it with this function:
var reinitDateTimeShortCuts = function() {
// Reinitialize the calendar and clock widgets by force, yuck.
if (typeof DateTimeShortcuts !== "undefined") {
$(".datetimeshortcuts").remove();
DateTimeShortcuts.init();
}
};
As anyone can see, this function removes datetimeshortcuts spans but doesn't remove "calendarbox module" and clockbox module" divs.
Then, call to the DateTimeShortcuts.init() again and again adds both the spans and the divs for all datetime fields on the page.
Thus, by adding 20 rows in formset, I have about 400 useless hidden divs on my page.
I see several ways to fix this bug.
1. Modify DateTimeShortcuts.js to use single hidden div for all datetime fields on the page
2. Modify DateTimeShortcuts.js init function to check if the datetime field is alreay initialized to avoid it's re-initialization, and exclude removing any DOM elements from reinitDateTimeShortCuts
3. Expand set of elements, removed in reinitDateTimeShortCuts and remove divs together with spans. Maybe it would be better to add reinit function into DateTimeShortcuts.js