This snippet will add a ‘Show Password’ checkbox to the Password field.
Step 1:
<input type="checkbox" onclick="showPassword()">Show Passwords
<script>
function showPassword() {
var x = document.getElementById("field_jjtjt");
var y = document.getElementById("field_conf_jjtjt");
if (x.type === "password") {
x.type = "text";
} else {
x.type = "password";
}
if (y.type === "password") {
y.type = "text";
} else {
y.type = "password";
}
}
</script>
Change jjtjt
to the FIELD KEY of the Password field in 2 places.
<input type="checkbox" id="show_password" name="show_password" onclick="showPassword();"> <label for="show_password">Show Password</label>I also took out the part about the confirmation field because I'm using the "show password" functionality in place of the confirmation, which is intended to prevent typos when using the password input.
Did some more exploration. I really like this approach with the toggle icon in the field. (see screenshot below) I happen to have font awesome already loaded. Reference: https://www.javascripttutorial.net/javascript-dom/javascript-toggle-password-visibility/ Note: I think this would work pretty well to add to other forms like log in and password reset since it appends the icon to the field with javascript instead of adding html...You just need to change the ID selector for the password field.
<script> const passwordField = document.querySelector("#field_1abwj2") passwordField.insertAdjacentHTML("afterend", "<a href=\"javascript: togglePassword();\" style=\"margin: -30px; cursor: pointer; color: #006A98;\"><i class=\"fa fa-eye-slash\" aria-hidden=\"true\" id=\"toggleIcon\"></i></a>"); const toggleIcon = document.querySelector("#toggleIcon"); function togglePassword() { // toggle the type attribute const type = passwordField.getAttribute("type") === "password" ? "text" : "password"; passwordField.setAttribute("type", type); // toggle the icon toggleIcon.classList.toggle("fa-eye-slash"); toggleIcon.classList.toggle("fa-eye"); } </script>
I have an updated version of a password show/hide toggle. I will try to submit it below, but I keep getting locked out.
Load your updated code in pastebin or gist and post the link.
this functionality is now part of formidable forms (password field settings)
Please login or Register to submit your answer
This works well in a regular formidable user registration form.
Any ideas on how to implement it when calling [frm-login]?
Thanks.