Ticket #3193: multi_hidden.patch
File multi_hidden.patch, 1.9 KB (added by , 18 years ago) |
---|
-
django/newforms/forms.py
4 4 5 5 from django.utils.datastructures import SortedDict, MultiValueDict 6 6 from django.utils.html import escape 7 from fields import Field 8 from widgets import TextInput, Textarea, HiddenInput 7 from fields import Field, MultipleChoiceField 8 from widgets import TextInput, Textarea, HiddenInput, MultipleHiddenInput 9 9 from util import StrAndUnicode, ErrorDict, ErrorList, ValidationError 10 10 11 11 __all__ = ('BaseForm', 'Form') … … 234 234 """ 235 235 Returns a string of HTML for representing this as an <input type="hidden">. 236 236 """ 237 if isinstance( self.field, MultipleChoiceField ): 238 return self.as_widget(MultipleHiddenInput(), attrs) 239 237 240 return self.as_widget(HiddenInput(), attrs) 238 241 239 242 def _data(self): -
django/newforms/widgets.py
3 3 """ 4 4 5 5 __all__ = ( 6 'Widget', 'TextInput', 'PasswordInput', 'HiddenInput', ' FileInput',6 'Widget', 'TextInput', 'PasswordInput', 'HiddenInput', 'MultipleHiddenInput', 'FileInput', 7 7 'Textarea', 'CheckboxInput', 8 8 'Select', 'SelectMultiple', 'RadioSelect', 'CheckboxSelectMultiple', 9 9 ) … … 87 87 input_type = 'hidden' 88 88 is_hidden = True 89 89 90 class MultipleHiddenInput(HiddenInput): 91 def render(self, name, value, attrs=None): 92 if not value: value = [] 93 final_attrs = self.build_attrs(attrs, type=self.input_type, name=name) 94 return u''.join( [ ( u'<input%s />' % flatatt( dict( value=val, **final_attrs ) ) ) for val in value] ) 95 90 96 class FileInput(Input): 91 97 input_type = 'file' 92 98