danirus / django-comments-xtd

A pluggable Django comments application with thread support, follow-up notifications, mail confirmation, like/dislike flags, moderation, a ReactJS plugin and Bootstrap 5.3.
https://django-comments-xtd.readthedocs.io
BSD 2-Clause "Simplified" License
594 stars 157 forks source link

fix __init__ in XtdCommentForm to keep origin fields parameters #315

Closed dest81 closed 3 years ago

dest81 commented 3 years ago

We shouldn't override the whole form field, we need only change particular attribute(s) of the field. For example in original CommentForm field name has max_length attribute which we are loosing/overriding in current code:

self.fields['name'] = forms.CharField(
            label=_("Name"),
            widget=forms.TextInput(attrs={'placeholder': _('name'),
                                          'class': 'form-control'}))

Solution is to change only widget and not whole field:

 self.fields['name'].widget = forms.TextInput(
            attrs={'placeholder': _('name'), 'class': 'form-control'})