Initially open collapsable fieldset class in admin

 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

  1. Collapsed stacked inlines by Aneon 4 years, 11 months ago
  2. FieldsetForm by Ciantic 7 years ago
  3. DRY Fieldsets by DrMeers 4 years, 10 months ago
  4. Forms splitted in fieldsets by gustavo80br 6 years ago
  5. Remove named field from fieldsets by dokterbob 4 years, 5 months ago

Comments

(Forgotten your password?)