﻿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
12913	Field.formfield() skips show_hidden_input parameter	Ilya Semenov	nobody	"The base models.Field.formfield() implementation silently skips show_hidden_input parameter for any Field with choices. That is incorrect, since show_hidden_input is a base parameter accepted by any form.Field, including TypedChoiceField:

{{{
#!python
# django/db/models/fields/__init__.py
class Field(object):
    # ...
    def formfield(self, form_class=forms.CharField, **kwargs):
        # ...
        if self.choices:
            # Many of the subclass-specific formfield arguments (min_value,
            # max_value) don't apply for choice fields, so be sure to only pass
            # the values that TypedChoiceField will understand.
            for k in kwargs.keys():
                if k not in ('coerce', 'empty_value', 'choices', 'required',
                             'widget', 'label', 'initial', 'help_text',
                             'error_messages'):
                    del kwargs[k]
        defaults.update(kwargs)
        return form_class(**defaults)

# django/forms/fields.py
class Field(object):
    # ...
    def __init__(self, required=True, widget=None, label=None, initial=None,
                 help_text=None, error_messages=None, show_hidden_initial=False):
}}}

That forces a user to use ugly constructions like:
{{{
#!python
def _formfield_with_hidden_initial(f):
	field = f.formfield()
	field.show_hidden_initial = True
	return field

class SimultaneousEditForm(forms.ModelForm):
	formfield_callback = _formfield_with_hidden_initial
}}}

With the proposed fix, the code above could be far more elegant (exactly as it supposed to be by model.Field.formfield() authors!) while not breaking anything:
{{{
#!python
class SimultaneousEditForm(forms.ModelForm):
	formfield_callback = lambda f: f.formfield(show_hidden_initial=True)
}}}
"		closed	Forms	dev		fixed			Accepted	1	0	1	0	0	0
