Ticket #2555: checkfield_fix_v2.patch
File checkfield_fix_v2.patch, 3.6 KB (added by , 18 years ago) |
---|
-
django/forms/__init__.py
449 449 (self.get_id(), self.__class__.__name__, 450 450 self.field_name, checked_html) 451 451 452 def run_validator(self, new_data, validator): 453 """ overridden to have the right behaviour with validators when no data is posted """ 454 if new_data.has_key('%s_hidden' % self.field_name) and not new_data.has_key(self.field_name): 455 # we use internally hidden field with right value 456 new_data[self.field_name] = new_data.get('%s_hidden' % self.field_name) 457 super(CheckboxField, self).run_validator(new_data, validator) 458 452 459 def html2python(data): 453 460 "Convert value from browser ('on' or '') to a Python boolean" 454 461 if data == 'on': 455 462 return True 456 return False 463 return False # if not set or set to 'off' 457 464 html2python = staticmethod(html2python) 458 465 459 466 class SelectField(FormField): -
django/contrib/admin/media/js/CheckBox.js
1 var CheckBox = { 2 checkboxes: [], 3 init: function() { 4 var inputs = document.getElementsByTagName('input'); 5 var num = 0; 6 for (i=0; i<inputs.length; i++) { 7 var inp = inputs[i]; 8 if (inp.getAttribute('type') == 'checkbox' && inp.className.match(/vCheckboxField/)) { 9 CheckBox.checkboxes[num] = inp; 10 inp.setAttribute('onclick', 'CheckBox.toggleCheckBox('+num+'); return true;'); 11 num++; 12 } 13 } 14 for (i=0;i<CheckBox.checkboxes.length;i++){ 15 CheckBox.createHiddenField(CheckBox.checkboxes[i].id); 16 } 17 }, 18 createHiddenField: function(id) { 19 if (document.getElementById(id + '_hidden') == null){ 20 var inp = document.getElementById(id); 21 var input_box = document.createElement('input'); 22 input_box.id = inp.id + '_hidden'; 23 input_box.name = inp.name + '_hidden'; 24 input_box.setAttribute('type', 'hidden'); 25 if (inp.checked) { 26 input_box.value = 'on'; 27 } else { 28 input_box.value = 'off'; 29 } 30 inp.parentNode.insertBefore(input_box, inp); 31 } 32 }, 33 toggleCheckBox: function(num) { 34 var vis = CheckBox.checkboxes[num]; 35 var hidden = document.getElementById(vis.id + '_hidden'); 36 if (vis.checked) { 37 hidden.value = 'on'; 38 } else { 39 hidden.value = 'off'; 40 } 41 } 42 } 43 44 addEvent(window, 'load', CheckBox.init); 45 No newline at end of file -
django/contrib/admin/views/main.py
85 85 js.append('js/urlify.js') 86 86 if opts.has_field_type(models.DateTimeField) or opts.has_field_type(models.TimeField) or opts.has_field_type(models.DateField): 87 87 js.extend(['js/calendar.js', 'js/admin/DateTimeShortcuts.js']) 88 if opts.has_field_type(models.BooleanField): 89 js.extend(['js/CheckBox.js']) 88 90 if opts.get_ordered_objects(): 89 91 js.extend(['js/getElementsBySelector.js', 'js/dom-drag.js' , 'js/admin/ordering.js']) 90 92 if opts.admin.js: