On Feb 19, 10:18 pm, "Justin Findlay" <[EMAIL PROTECTED]> wrote: > On Jan 25, 1:16 pm, "canen" <[EMAIL PROTECTED]> wrote: > > > Answering my own question: > Thanks for the example! I created another, but it uses initial data, and an object representing the info. class Postal(object): def __init__(self, line1='', line2='', line3='', code=''): self.line1 = line1 self.line2 = line2 self.line3 = line3 self.code = code class PostalWidget(django.newforms.widgets.MultiWidget): def __init__(self, attrs=None): widgets = (django.newforms.widgets.TextInput(), django.newforms.widgets.TextInput(), django.newforms.widgets.TextInput(), django.newforms.widgets.TextInput()) super(PostalWidget, self).__init__(widgets, attrs=attrs) def decompress(self, value): if value: return [value.line1, value.line2, value.line3, value.code] return [None, None, None, None] class PostalField(django.newforms.fields.MultiValueField): widget = PostalWidget def __init__(self, required=True, widget=None, label=None, initial=None): fields = (django.newforms.fields.CharField(), django.newforms.fields.CharField(), django.newforms.fields.CharField(), django.newforms.fields.CharField()) super(PostalField, self).__init__(fields=fields, widget=widget, label=label, initial=initial) def compress(self, data_list): if data_list: return Postal(data_list[0], data_list[1], data_list[2], data_list[3]) return None class EnrolmentForm(django.newforms.Form): name = django.newforms.fields.CharField(label='Name') surname = django.newforms.fields.CharField(label='Surname') postalField = PostalField() data= {'name':'piet', 'surname':'plesier', 'postalField_0' : 'cs', 'postalField_1' : 'pretoria', 'postalField_2' : 'Hatfield' ,'postalField_3' : '0084'} #initial= {'name':'piet', 'surname':'plesier', 'postalField' : Postal(line1='pompies')} initial= {'name':'piet', 'surname':'plesier'} f = EnrolmentForm(initial=initial) print f.as_p() f = EnrolmentForm(data=data) print f.is_valid() print f.errors print f.clean_data > > The widget can be declared as part of the field, e.g. > > > # Field > > class MoneyField(MultiValueField): > > def __init__(self, currency=(), amount=(), required=True, > > widget=None, label=None, initial=None): > > widget = widget or MoneyWidget(currency=currency, > > amount=amount) > > ..... > > Canen, do you have the time to work out a full example? After much > trying I'm still not able to repeat the example without having to use > the double tuple values. > > Justin --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~----------~----~----~----~------~----~------~--~---