Prometheus
Prometheus

Reputation: 33655

Password type filed in crispy forms, how?

I'm using crispy forms in Django. Below you can see I have set the password field type as password. However, when the form is rendered the input is still in clear text and the type still shows as type="text" is there a trick I have missed here?

def __init__(self, *args, **kwargs):
    super(UserRegistrationForm, self).__init__(*args, **kwargs)

    self.helper = FormHelper()
    self.helper.form_method = 'post'
    # turn off HTML5 validation
    self.helper.attrs = {'novalidate': ''}
    self.helper.form_show_labels = False

    self.helper.layout = Layout(

        Field('email_mobile', type="hidden"),

        Fieldset(
            'Enter a password',
            PrependedText('password', '<i class="fa fa-key"></i>',
                          placeholder='Password',
                          autocomplete='off', type="password"),
        ),

    )

Upvotes: 1

Views: 678

Answers (1)

Wolph
Wolph

Reputation: 80091

The PrependedText isn't a simple input field so just passing along type doesn't really work. The type should be added to the widget, not the field.

So try this instead:

PrependedText(
    'password',
    '<i class="fa fa-key"></i>',
    placeholder='Password',
    widget=PasswordInput,
    autocomplete='off',
)

Upvotes: 1

Related Questions