[Fixed]-Django: Add a placeholder text to default comment textarea field

1👍

In __init__ method of form (and not only there) you can modify any attributes of fields, even swap fields with other types. All fields are stored in dictionary self.fields. So all you need to do is:

class CommentForm(CommentDetailsForm):
    email = forms.EmailField(label=_("E-mail address"), required=False)

    def __init__(self, *args, **kwargs):
        super(CommentForm, self).__init__(*args, **kwargs)
        self.fields['field_to_add_placeholder_to'].widget.attrs['placeholder'] = "your placeholder"

Leave a comment