Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cannot have a composite form when forms have fields with the same names #3

Open
zsoldosp opened this issue Sep 5, 2012 · 2 comments

Comments

@zsoldosp
Copy link

zsoldosp commented Sep 5, 2012

Below is the sample code to illustrate. I picked the well-known online shop example, focusing on the checkout step, when billing and delivery addresses are specified.

>>> from composite_form.forms import CompositeForm
>>> from django import forms
>>> class Address(forms.Form):
...     address = forms.CharField('address details')
...
>>> class BillingAddress(Address):
...     def __init__(self, *args, **kwargs):
...         kwargs['prefix'] = kwargs.get('prefix', 'billing')
...         super(BillingAddress, self).__init__(*args, **kwargs)
...
>>> class DeliveryAddress(Address):
...     def __init__(self, *args, **kwargs):
...         kwargs['prefix'] = kwargs.get('prefix', 'delivery')
...         super(DeliveryAddress, self).__init__(*args, **kwargs)
...
>>> class CheckoutAddressForm(CompositeForm):
...     form_list = [BillingAddress, DeliveryAddress]
...
>>> checkout_form = CheckoutAddressForm(data={'billing-address': 'Billing Address details', 'delivery-address': 'Delivery Address details'})
>>> checkout_form.is_valid()
True
>>> checkout_form.cleaned_data
{'address': u'Delivery Address details'}
>>> # I would have expected two addresses with prefixes there or that __init__ failed with an error telling me same field names are not supported
@t0ster
Copy link
Owner

t0ster commented Sep 5, 2012

Thanks!

Pull request? :)

@zsoldosp
Copy link
Author

zsoldosp commented Sep 5, 2012

I've offered two alternative solutions, and you are the project owner/lead, you should decide which direction you want to take this project. Failing fast & hard is easy, supporting prefixes might lead to the land of dragons :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants