﻿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
27370	"Django's Select widget adds a required=""required"" attribute, even if created with empty_label=True"	alexpirine	nobody	"I didn't think it was wrong in HTML, but the W3C validator says so, and after reading this discussion, it seems to be right:

https://github.com/validator/validator/issues/47

This is how I could explain it:

If a form field is required and has the `empty_label=True` argument, the generated `<select>` will have a `required=""required""` attribute. This doesn't make sense since the first item will be selected anyways, and there is no way for the user to ''unselect'' a value.

So, the `required=""required""` attribute is useless.

Example:

{{{#!python
class TestForm(forms.Form):
    some_field = forms.ModelChoiceField(queryset=SomeModel.objects.all(), empty_label=None)
}}}

results in:

{{{#!text/html
<select id=""id_some_field"" name=""some_field"" required>
<option value=""1"">Value 1</option>
<option value=""2"">Value 2</option>
<option value=""3"">Value 3</option>
<!-- ... -->
</select>
}}}

You can check the following code using the [https://validator.w3.org/#validate_by_input W3C validation service]:


{{{#!text/html
<!DOCTYPE html>
<html lang=""en"">
<head>
  <meta charset=""utf-8"">
  <title>Validation test</title>
</head>
<body>
  <select id=""id_some_field"" name=""some_field"" required>
    <option value=""1"">Value 1</option>
    <option value=""2"">Value 2</option>
    <option value=""3"">Value 3</option>
    <!-- ... -->
  </select>
</body>
</html>
}}}
"	Bug	new	Forms	1.10	Normal		HTML,Select,wdiget,ModelChoiceField		Unreviewed	0	0	0	0	0	0
