﻿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
36317	ModelChoiceField cannot be hidden by default	Josh Piasecki		"hello all, I have run into something that feels like a bug to me, but i could be wrong there may be a reason for this behavior.

I have added a custom action form to my Admin page.
my goal is to default these fields to hidden and only show them when the associated action is selected.
I have accomplished this with JS, however there is a delay before it is loaded and there is a small layout shift.
the form contains two fields, the relevant code is below.

{{{
  choice = ModelChoiceField(
        ...
        widget=Select(
            attrs={
                ""style"": ""display: none;""
            }
        ),
    )

  date = DateField(
        ...
        widget=DateInput(
            attrs={
                ""style"": ""display: none;"",
            }
        ),
    )
}}}


the DateInput is appropriately hidden when the template is rendered and requires no JS to hide the input initially.
however, because the way dropdowns are rendered in html. the ModelChoiceField is not correctly hidden.

the rendered html basically looks like this:
{{{

<label>
  <select style=""display: none;"" />
  <span />
</label>
}}}

the problem is that the `<select>` element is hidden by default and the `<span>` is what the user actually interacts with.

so the expected behavior is that when `display: none;` is set on the widget, the widget is hidden.

it would be nice if Django was smart enough to set `display: none;` on all the associated elements to the widget for this particular case.



"	Bug	closed	Forms	5.2	Normal	invalid			Unreviewed	0	0	0	0	0	0
