-
Notifications
You must be signed in to change notification settings - Fork 293
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
COUNTRIES_FIRST_BREAK prevents the form widget from being required? #280
Comments
Interesting, this is because of this, in def use_required_attribute(self, initial):
"""
Don't render 'required' if the first <option> has a value, as that's
invalid HTML.
"""
use_required_attribute = super().use_required_attribute(initial)
# 'required' is always okay for <select multiple>.
if self.allow_multiple_selected:
return use_required_attribute
first_choice = next(iter(self.choices), None)
return use_required_attribute and first_choice is not None and self._choice_has_empty_value(first_choice) See https://code.djangoproject.com/ticket/27370 - "The first child option element of a select element with a required attribute, and without a multiple attribute, and without a size attribute whose value is greater than 1, must have either an empty value attribute, or must have no text content." It seems like the validator is requiring the first element to be empty, though from my reading the actual HTML spec doesn't require that the placeholder is the first Anyway, assuming that's not something we want to work-around, maybe the solution is documentation that setting COUNTRIES_FIRST_BREAK will make the widget not render |
It seems that if I set
COUNTRIES_FIRST_BREAK
, the widget doesn't render therequired
attribute?with these settings:
If I remove COUNTRIES_FIRST_BREAK from settings it works as expected (
required=""
in the select tag)With
django-countries==5.5
Django==2.2.6
The text was updated successfully, but these errors were encountered: