implement logic for a show password button
This commit is contained in:
22
static/javascript/show_password.js
Normal file
22
static/javascript/show_password.js
Normal file
@@ -0,0 +1,22 @@
|
||||
const showPasswordButtons = document.getElementsByClassName(
|
||||
"show_password_toggle",
|
||||
);
|
||||
|
||||
for (const button of showPasswordButtons) {
|
||||
button.addEventListener("click", function () {
|
||||
const input = this.parentElement.querySelector(
|
||||
"input[type='password'], input[type='text']",
|
||||
);
|
||||
if (!input) return;
|
||||
const isHidden = input.type === "password";
|
||||
input.type = isHidden ? "text" : "password";
|
||||
|
||||
if (isHidden) {
|
||||
this.classList.add("open");
|
||||
this.classList.remove("closed");
|
||||
} else {
|
||||
this.classList.remove("open");
|
||||
this.classList.add("closed");
|
||||
}
|
||||
});
|
||||
}
|
||||
Reference in New Issue
Block a user