Hans de Jong
Hans de Jong

Reputation: 2078

django forms use multiple widget for field

I would like to use multiple widgets on 1 form field in django.

password = forms.CharField(required=True,
        widget=forms.PasswordInput,
        widget=forms.TextInput(attrs={'placeholder': 'Password:'}))

When I use it like this, i get the error: "keyword argument repeated " I understand that I am using widget= twice, but I cant figure out how else to do it

Upvotes: 0

Views: 7024

Answers (1)

Kamil Rykowski
Kamil Rykowski

Reputation: 1459

PasswordInput extends TextInputt so you can simply do it like this:

    password = forms.CharField(required=True, widget=forms.PasswordInput(attrs={'placeholder': 'Password:'}))

Upvotes: 6

Related Questions