Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use more than one widget in a Django field?

I have a specific field in a form which needs to have a custom attribute AND we styled as a password box. Currently I have:

login_password = forms.CharField(label=(u'password'))

But I need both of these:

widget=forms.TextInput(attrs={'placeholder': 'password'})
widget=forms.PasswordInput(render_value=False)

How can I make it so the field uses these two widgets? I've read about MultiWidget but I'm not sure if this is what I need to use or how exactly to use it.


1 Answers

PasswordInput accepts attrs as well.

login_password = forms.CharField(label=u'password', widget=forms.PasswordInput(render_value=False, attrs={'placeholder': 'password'}))
like image 197
DrTyrsa Avatar answered Dec 14 '25 01:12

DrTyrsa



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!