- Author:
- ralfzen
- Posted:
- September 17, 2010
- Language:
- JavaScript
- Version:
- 1.2
- Score:
- 1 (after 1 ratings)
It's just an extension for the admin. Replace the collapse.js (collapse.min.js) and use it like this in the admin fieldset option: ´´'classes': ['collapse', 'open']´´. Without the 'open'-class, it will work as usual. Needs possibly fixing for IE <= 8 because IE doesn't support the ´´:not´´ selector.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 | (function($) {
$(document).ready(function() {
// Add anchor tag for Show/Hide link
$("fieldset.collapse").each(function(i, elem) {
// Don't hide if fields in this fieldset have errors
if ( $(elem).find("div.errors").length == 0 ) {
// if extra-class open do not collapse initially
if ( !$(elem).hasClass('open') ) {
$(elem).addClass("collapsed");
$(elem).find("h2").first().append(' (<a id="fieldsetcollapser' +
i +'" class="collapse-toggle" href="#">' + gettext("Show") +
'</a>)');
} else {
$(elem).find("h2").first().append(' (<a id="fieldsetcollapser' +
i +'" class="collapse-toggle" href="#">' + gettext("Hide") +
'</a>)');
}
}
});
hide = function() {
$(this).text(gettext("Show"));
$(this).closest("fieldset").addClass("collapsed");
return false;
};
show = function() {
$(this).text(gettext("Hide"));
$(this).closest("fieldset").removeClass("collapsed");
return false;
};
// Add close-toggle to anchor tag
$("fieldset.collapse:not(.open) a.collapse-toggle").toggle(
show,
hide
);
// Add open-toggle to anchor tag
$("fieldset.collapse.open a.collapse-toggle").toggle(
hide,
show
);
});
})(django.jQuery);
|
More like this
- Django Collapsed Stacked Inlines by applecat 1 year, 9 months ago
- Django Collapsed Stacked Inlines by mkarajohn 3 years, 10 months ago
- Dynamically adding forms to a formset. OOP version. by halfnibble 9 years, 6 months ago
- Convert multiple select for m2m to multiple checkboxes in django admin form by abidibo 11 years, 7 months ago
- Django admin inline ordering - javascript only implementation by ojhilt 11 years, 11 months ago
Comments
Please login first before commenting.