Ticket #2640: checkboxfield.patch

File checkboxfield.patch, 1.1 KB (added by torbjornthorsen@…, 18 years ago)

Patch for using is_required on CheckboxField

  • mytrunk/django/forms/__init__.py

     
    434434            (self.get_id(), self.field_name, escape(data))
    435435
    436436class CheckboxField(FormField):
    437     def __init__(self, field_name, checked_by_default=False, validator_list=None):
     437    def __init__(self, field_name, checked_by_default=False, validator_list=None,is_required=True):
    438438        if validator_list is None: validator_list = []
    439439        self.field_name = field_name
    440440        self.checked_by_default = checked_by_default
    441         self.is_required = False # because the validator looks for these
     441        self.is_required = is_required
    442442        self.validator_list = validator_list[:]
    443443
    444444    def render(self, data):
     
    451451
    452452    def html2python(data):
    453453        "Convert value from browser ('on' or '') to a Python boolean"
    454         if data == 'on':
    455             return True
    456         return False
     454        return True
    457455    html2python = staticmethod(html2python)
    458456
    459457class SelectField(FormField):
Back to Top