diff options
| author | Hasan Ramezani <hasan.r67@gmail.com> | 2019-05-05 01:26:37 +0200 |
|---|---|---|
| committer | Mariusz Felisiak <felisiak.mariusz@gmail.com> | 2019-05-08 12:46:30 +0200 |
| commit | f038214d917c982613f5a15db8dfe325b1f7479b (patch) | |
| tree | 18568b95d012b8466d1a498f594d2dcfd65bb229 /django/forms/widgets.py | |
| parent | ef9f2eb69c9396683cefa742bc7d0a0792090e8d (diff) | |
Fixed #29056 -- Fixed HTML5 validation of required SelectDateWidget.
placeholder is required for "select" with "required" attribute.
Diffstat (limited to 'django/forms/widgets.py')
| -rw-r--r-- | django/forms/widgets.py | 18 |
1 files changed, 15 insertions, 3 deletions
diff --git a/django/forms/widgets.py b/django/forms/widgets.py index e944091f0d..c8ec3c35d5 100644 --- a/django/forms/widgets.py +++ b/django/forms/widgets.py @@ -979,7 +979,11 @@ class SelectDateWidget(Widget): date_context['year'] = self.select_widget(attrs, choices=year_choices).get_context( name=year_name, value=context['widget']['value']['year'], - attrs={**context['widget']['attrs'], 'id': 'id_%s' % year_name}, + attrs={ + **context['widget']['attrs'], + 'id': 'id_%s' % year_name, + 'placeholder': _('Year') if self.is_required else False, + }, ) month_choices = list(self.months.items()) if not self.is_required: @@ -988,7 +992,11 @@ class SelectDateWidget(Widget): date_context['month'] = self.select_widget(attrs, choices=month_choices).get_context( name=month_name, value=context['widget']['value']['month'], - attrs={**context['widget']['attrs'], 'id': 'id_%s' % month_name}, + attrs={ + **context['widget']['attrs'], + 'id': 'id_%s' % month_name, + 'placeholder': _('Month') if self.is_required else False, + }, ) day_choices = [(i, i) for i in range(1, 32)] if not self.is_required: @@ -997,7 +1005,11 @@ class SelectDateWidget(Widget): date_context['day'] = self.select_widget(attrs, choices=day_choices,).get_context( name=day_name, value=context['widget']['value']['day'], - attrs={**context['widget']['attrs'], 'id': 'id_%s' % day_name}, + attrs={ + **context['widget']['attrs'], + 'id': 'id_%s' % day_name, + 'placeholder': _('Day') if self.is_required else False, + }, ) subwidgets = [] for field in self._parse_date_fmt(): |
