Django

Code

Changeset 6563

Show
Ignore:
Timestamp:
10/20/07 07:21:07 (11 months ago)
Author:
mtredinnick
Message:

Changed newforms.CheckboxInput? widget to return False as its value when not
include in the form (since HTML form submission doesn't send unselected check
boxes). Patch from SmileyChris?. Refs #5104.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • django/trunk/django/newforms/widgets.py

    r6451 r6563  
    170170            final_attrs['value'] = force_unicode(value) # Only add the 'value' attribute if a value is non-empty. 
    171171        return u'<input%s />' % flatatt(final_attrs) 
     172 
     173    def value_from_datadict(self, data, files, name): 
     174        if name not in data: 
     175            # A missing value means False because HTML form submission does not 
     176            # send results for unselected checkboxes. 
     177            return False 
     178        return super(CheckboxInput, self).value_from_datadict(data, files, name) 
    172179 
    173180class Select(Widget): 
  • django/trunk/tests/regressiontests/forms/widgets.py

    r6379 r6563  
    276276>>> w.render('greeting', None) 
    277277u'<input type="checkbox" name="greeting" />' 
     278 
     279The CheckboxInput widget will return False if the key is not found in the data 
     280dictionary (because HTML form submission doesn't send any result for unchecked 
     281checkboxes). 
     282>>> w.value_from_datadict({}, {}, 'testing') 
     283False 
    278284 
    279285# Select Widget ###############################################################