Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Password Toggle #139

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions allauth_ui/templates/components/form.html
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,13 @@
{% if render_fields == "true" %}
{% for field in form.visible_fields %}
{% if field.name != "remember" %}
{% #form_field field=field %}
{% /form_field %}
{% if field.name == "password" %}
{% #form_field field=field is_password='true' %}
{% /form_field %}
{% else %}
{% #form_field field=field %}
{% /form_field %}
{% endif %}
{% endif %}
{% endfor %}
{% endif %}
Expand Down
32 changes: 31 additions & 1 deletion allauth_ui/templates/components/form_field.html
Original file line number Diff line number Diff line change
@@ -1,11 +1,41 @@
{% load slippers %}
{% load widget_tweaks %}
{% var is_password=is_password|default:"false" %}

<script>
function togglePassword() {
const passwordField = document.querySelector('.password-field');
const toggleButton = document.querySelector('button');

if (passwordField.type === "password") {
passwordField.type = "text";
toggleButton.textContent = "Hide";
} else {
passwordField.type = "password";
toggleButton.textContent = "Show";
}
}
</script>


<label class="label" for="{{ field.id_for_label }}">
<span class="label-text">{{ field.label }}</span>
</label>
{% if field.errors %}
{% render_field field placeholder="" class="w-full input input-bordered text-primary input-error" %}
{% else %}
{% render_field field placeholder="" class="w-full input input-bordered text-primary" %}
{% if is_password == 'true' %}
<div class="relative flex w-full">
{% render_field field placeholder="" class="w-full input input-bordered text-primary password-field"%}
<button type="button" onclick="togglePassword()"
class="btn btn-neutral text-gray-500 hover:text-gray-700 text-sm">
Show
</button>

</div>
{% else %}
{% render_field field placeholder="" class="w-full input input-bordered text-primary" %}
{% endif %}
{% endif %}
{% for error in field.errors %}
<span class="flex items-center max-w-xs mt-1 ml-1 text-xs font-medium tracking-wide text-error">{{ error }}</span>
Expand Down