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

DRAFT: Fix typeerror when changing type back to password #90

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

dan-jensen
Copy link
Contributor

@dan-jensen dan-jensen commented Jun 21, 2022

WARNING: This is a draft. The changes to the .js file have not yet been reflected in the min.js file.

Description

After the password input has been converted to text, there is no
input matching type=password. However, the JS assumed there is which
resuled in a TypeError due to a null result when it looked for the
input. This fixes the problem by selecting by class instead.

Motivation and Context

This fixes a bug that occurs when you click to convert a text input back into a password input.

How Has This Been Tested?

Tested locally.

Screenshots (if appropriate)

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)

Checklist

  • My code follows the code style of this project.

@dan-jensen
Copy link
Contributor Author

@coliff what do you think of these changes?

@coliff coliff self-requested a review June 21, 2022 23:02
@dan-jensen
Copy link
Contributor Author

dan-jensen commented Jun 21, 2022

The behavior was actually still a little buggy. Specifically, the button could get out of sync, so clicking would have no effect. This fixes the bugginess by eliminating the nested onclick. So if you're willing to make a bigger change to the JS (although still non-breaking) I would recommend this:

const passwordInput = document.querySelector("[type='password']");
const passwordToggle = document.getElementById("toggle-password");

passwordInput.classList.add("input-password");
passwordToggle.classList.remove("d-none");

passwordToggle.onclick = function () {
  if (passwordInput.type === "password") {
    passwordInput.type = "text";
    passwordToggle.setAttribute("aria-label", "Obscure the value.");
  } else {
    passwordInput.type = "password";
    passwordToggle.setAttribute("aria-label", "Reveal the value.");
  }
  passwordInput.focus();
};

@dan-jensen dan-jensen force-pushed the fix-typeerror-when-changing-type-back-to-password branch from 172ded6 to 2b83e9e Compare June 21, 2022 23:23
@coliff coliff marked this pull request as draft June 28, 2022 08:12
After the password input has been converted to text, there is no
input matching type=password. However, the JS assumed there is which
resuled in a TypeError due to a null result when it looked for the
input. This fixes the problem by selecting by class instead.
@coliff coliff force-pushed the fix-typeerror-when-changing-type-back-to-password branch from dc3685e to d5a919b Compare September 4, 2023 12:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant