Ticket #2545: collapse_empty.2.patch
File collapse_empty.2.patch, 3.3 KB (added by , 18 years ago) |
---|
-
django/contrib/admin/media/js/admin/CollapsedFieldsets.js
13 13 var CollapsedFieldsets = { 14 14 collapse_re: /\bcollapse\b/, // Class of fieldsets that should be dealt with. 15 15 collapsed_re: /\bcollapsed\b/, // Class that fieldsets get when they're hidden. 16 collapse_empty_re: /\bcollapse_empty\b/, // Extra class which only hides fieldsets with no values (still requires "collapse" class) 16 17 collapsed_class: 'collapsed', 17 18 init: function() { 18 19 var fieldsets = document.getElementsByTagName('fieldset'); … … 21 22 // Collapse this fieldset if it has the correct class, and if it 22 23 // doesn't have any errors. (Collapsing shouldn't apply in the case 23 24 // of error messages.) 24 if (fs.className.match(CollapsedFieldsets.collapse_re) && !CollapsedFieldsets.fieldset_has_errors(fs)) { 25 if (fs.className.match(CollapsedFieldsets.collapse_re) 26 && !CollapsedFieldsets.fieldset_has_errors(fs) 27 && (!fs.className.match(CollapsedFieldsets.collapse_empty_re) || !CollapsedFieldsets.fieldset_not_empty(fs))) { 25 28 collapsed_seen = true; 26 29 // Give it an additional class, used by CSS to hide it. 27 30 fs.className += ' ' + CollapsedFieldsets.collapsed_class; … … 53 56 } 54 57 return false; 55 58 }, 59 fieldset_not_empty: function(fs) { 60 // Returns true if any fields in the fieldset have values. 61 var tags = new Array('select', 'textarea', 'input'); 62 var tag; 63 for (var i=0; i<tags.length; i++) { 64 tag = tags[i]; 65 var objs = fs.getElementsByTagName(tag); 66 for (var j=0; j<objs.length; j++) { 67 o = objs[j]; 68 if (tag=='input' && o.type=='checkbox') { 69 if (o.checked) { 70 return true; 71 } 72 } 73 else if (tag!='input' || o.type!='radio') { 74 if (o.value) { 75 return true; 76 } 77 } 78 } 79 } 80 return false; 81 }, 56 82 show: function(fieldset_index) { 57 83 var fs = document.getElementsByTagName('fieldset')[fieldset_index]; 58 84 // Remove the class name that causes the "display: none". -
docs/model-api.txt
1171 1171 'classes': 'wide extrapretty', 1172 1172 } 1173 1173 1174 Twouseful classes defined by the default admin-site stylesheet are1174 Some useful classes defined by the default admin-site stylesheet are 1175 1175 ``collapse`` and ``wide``. Fieldsets with the ``collapse`` style will be 1176 1176 initially collapsed in the admin and replaced with a small "click to expand" 1177 link. Fieldsets with the ``wide`` style will be given extra horizontal space. 1177 link. Use both ``collapse`` and ``collapse_empty`` to only initially collapse 1178 the fieldset if all its fields are blank. Fieldsets with the ``wide`` style 1179 will be given extra horizontal space. 1178 1180 1179 1181 ``description`` 1180 1182 ~~~~~~~~~~~~~~~