Ticket #3193: multi_hidden.patch

File multi_hidden.patch, 1.9 KB (added by Honza Král <Honza.Kral@…>, 18 years ago)

implementation of MultipleHiddenInput

  • django/newforms/forms.py

     
    44
    55from django.utils.datastructures import SortedDict, MultiValueDict
    66from django.utils.html import escape
    7 from fields import Field
    8 from widgets import TextInput, Textarea, HiddenInput
     7from fields import Field, MultipleChoiceField
     8from widgets import TextInput, Textarea, HiddenInput, MultipleHiddenInput
    99from util import StrAndUnicode, ErrorDict, ErrorList, ValidationError
    1010
    1111__all__ = ('BaseForm', 'Form')
     
    234234        """
    235235        Returns a string of HTML for representing this as an <input type="hidden">.
    236236        """
     237        if isinstance( self.field, MultipleChoiceField ):
     238            return self.as_widget(MultipleHiddenInput(), attrs)
     239
    237240        return self.as_widget(HiddenInput(), attrs)
    238241
    239242    def _data(self):
  • django/newforms/widgets.py

     
    33"""
    44
    55__all__ = (
    6     'Widget', 'TextInput', 'PasswordInput', 'HiddenInput', 'FileInput',
     6    'Widget', 'TextInput', 'PasswordInput', 'HiddenInput', 'MultipleHiddenInput', 'FileInput',
    77    'Textarea', 'CheckboxInput',
    88    'Select', 'SelectMultiple', 'RadioSelect', 'CheckboxSelectMultiple',
    99)
     
    8787    input_type = 'hidden'
    8888    is_hidden = True
    8989
     90class 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
    9096class FileInput(Input):
    9197    input_type = 'file'
    9298
Back to Top