Coder Social home page Coder Social logo

django-composite-form's People

Contributors

t0ster avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

django-composite-form's Issues

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

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

form instance is incorrectly propagated to other forms

if instance is None a previous kwargs dictionary is used in next iteration.
Affected code (forms.CompositeForm.__init__):

        for form in self.form_list:
            if self.get_form_instance(form):
                kwargs.update({"instance": self.get_form_instance(form)})
            self._form_instances[form] = form(data, files, *args, **kwargs)

a possible fix:

        for form in self.form_list:
            kwargs = initkwargs.copy()
            if self.get_form_instance(form):
                kwargs.update({"instance": self.get_form_instance(form)})
            self._form_instances[form] = form(data, files, *args, **kwargs)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.