For me, a custom widget (that could use its own template) looks cleaner. Something like birth_date=DatePicker() seems more readable and doesn't require repeating "tag='duet-date-picker'"" each time. If you prefer your one-line version, you could override the input.html template and make the tag name a variable. I wouldn't advocate for that change in Django's input.html template. On Friday, July 24, 2020 at 8:07:10 AM UTC-4 1337 Shadow Hacker wrote:
> For those who haven't followed, I'll try to re-explain prior to showing > example code: > > Currently, we can change the attrs declaratively without going through > whatever override/boilerplate. > > In 2020, we can use custom elements, which means that we also need to > change the tag name. > > We don't need special constructors because custom elements configures with > attrs, which are already available declaratively. > > Now for some examples: > > class YourForm(forms.ModelForm): > class Meta: > model = YourModel > widgets = dict( > birth_date=forms.TextInput(attrs={'type': 'date', 'max': > max_date}) > ) > > Victory ! We now have a native date field with a one-liner ! But what if > we want to change to a duet date picker ? You need to change the tag name > from "input" to "duet-tag-picker": > > forms.TextInput(attrs={'type': 'date', 'max': max_date}, > tag='duet-date-picker') > > It seems the reason for being able to set attrs this way but not the tag > name too is because this was designed prior to the custom element W3C > standard that's now implemented in every browser. > > -- You received this message because you are subscribed to the Google Groups "Django developers (Contributions to Django itself)" group. To unsubscribe from this group and stop receiving emails from it, send an email to django-developers+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/django-developers/06c4b43d-2f30-47db-93ae-5c12b75457f3n%40googlegroups.com.