Ticket #11303: HiddenBooleanInput.diff

File HiddenBooleanInput.diff, 1.8 KB (added by Ilya Semenov, 15 years ago)
  • django/forms/fields.py

     
    2828from django.utils.encoding import smart_unicode, smart_str
    2929
    3030from util import ErrorList, ValidationError
    31 from widgets import TextInput, PasswordInput, HiddenInput, MultipleHiddenInput, FileInput, CheckboxInput, Select, NullBooleanSelect, SelectMultiple, DateInput, DateTimeInput, TimeInput, SplitDateTimeWidget, SplitHiddenDateTimeWidget
     31from widgets import TextInput, PasswordInput, HiddenInput, HiddenBooleanInput, MultipleHiddenInput, FileInput, CheckboxInput, Select, NullBooleanSelect, SelectMultiple, DateInput, DateTimeInput, TimeInput, SplitDateTimeWidget, SplitHiddenDateTimeWidget
    3232
    3333__all__ = (
    3434    'Field', 'CharField', 'IntegerField',
     
    581581
    582582class BooleanField(Field):
    583583    widget = CheckboxInput
     584    hidden_widget = HiddenBooleanInput
    584585
    585586    def clean(self, value):
    586587        """Returns a Python boolean object."""
  • django/forms/widgets.py

     
    234234    input_type = 'hidden'
    235235    is_hidden = True
    236236
     237class HiddenBooleanInput(HiddenInput):
     238    """
     239    A widget that handles <input type="hidden"> for boolean data.
     240    The only difference from the original hidden input is that
     241    it will not place a "0" for False.
     242    """
     243    def render(self, name, value, attrs=None):
     244        if not value: value = None
     245        return super(HiddenBooleanInput, self).render(name, value, attrs)
     246
    237247class MultipleHiddenInput(HiddenInput):
    238248    """
    239249    A widget that handles <input type="hidden"> for fields that have a list
Back to Top