marimuthu
marimuthu

Reputation: 81

How to set password show/hide eye button in Django form

First, I will try to solve this problem using native HTML and jquery, but I want to solve this problem in Django form without any script.

I will try this source code.

My expected output is put this same example in the above link to Django form.

Upvotes: 6

Views: 8209

Answers (2)

Hugo
Hugo

Reputation: 109

I see this question has more than 4 years, but as I see a response from months ago in @muthu response, I add mine here.

I've searched for HTML support for this show/hide icon. Nothing yet. I haven't found any Django module supporting this, so I have created mine today. It adds a new Field to Django that shows this eye icon.

https://pypi.org/project/django-password-eye/1.0.3/

Upvotes: 0

Marimuthu
Marimuthu

Reputation: 146

class CustomerLoginFrom(ModelForm):
    class Meta:
        model = UserLogin
        fields = ['user_name','password']
        labels = {
            "user_name": "*Username",
            "password": "*Password"
        }    
        widgets = {
            "user_name":  TextInput(attrs={'placeholder':'ex:test','autocomplete': 'off'}), 
            "password": PasswordInput(attrs={'placeholder':'********','autocomplete': 'off','data-toggle': 'password'}),
        }

<input type="password" id="password" name="password" class="form-control" data-toggle="password">

Django password field to add HTML attributes directly to Django form attrs, it works for me.

Upvotes: 2

Related Questions