﻿id	summary	reporter	owner	description	type	status	component	version	severity	resolution	keywords	cc	stage	has_patch	needs_docs	needs_tests	needs_better_patch	easy	ui_ux
35949	Add formset_kwargs keyword argument to BaseFormSet	Richard Brockie		"Hi,

I find it useful when validating formsets to sometimes define and set an attribute that can be used during validation.

{{{
class MyFormSet(BaseFormSet):
    useful_attribute = None

    def clean(self):
        super().clean()

        # validation code using self.useful_attribute...


# usage in a view...

    the_formset = formset_factory(MyForm, formset=MyFormSet, extra=0)

    bound_formset = the_formset(initial=initial_results,
    	form_kwargs=form_kwargs)

    bound_formset.useful_attribute = useful_value
}}}

I'm wondering if formset_kwargs could be added to BaseFormSet to follow the form_kwargs pattern. The suggested usage would be something like this:

{{{
class MyFormSet(BaseFormSet):
    def __init__(self, useful_attribute, *args, **kwargs):
        self.useful_attribute = useful_attribute
        super().__init__(*args, **kwargs)

    def clean(self):
        super().clean()

        # validation code using self.useful_attribute...


# usage in a view...

    the_formset = formset_factory(MyForm, formset=MyFormSet, extra=0)

    bound_formset = the_formset(initial=initial_results,
    	form_kwargs=form_kwargs,
    	formset_kwargs={""useful_attribute"": useful_value})
}}}

The kwargs provided in formset_kwargs would then be passed to MyFormSet when it is instantiated. 
"	New feature	closed	Forms	5.1	Normal	wontfix	formset validation	Richard Brockie David Smith	Unreviewed	0	0	0	0	0	0
