Laravel-Backpack / community-forum

A workspace to discuss improvement and feature ideas, before they're actually implemented.
28 stars 0 forks source link

Show/hide toggle for password field. #794

Closed karandatwani92 closed 6 months ago

karandatwani92 commented 6 months ago

We added Show/hide password button toggler on the login page. https://github.com/Laravel-Backpack/theme-tabler/pull/154

can we do the same to our password field?

horgolzari98 commented 6 months ago

Certainly! If you have implemented a show/hide password button toggler on the login page using Laravel Backpack/Theme Tabler, you can apply a similar approach to add a show/hide toggle functionality to your password field.

Assuming you have a form with a password input field, you can use JavaScript/jQuery to toggle the input type between "password" and "text" based on a button click. Here's a basic example using jQuery:

  1. Include jQuery: Make sure you include jQuery in your project. You can include it from a CDN or download it locally.

    <!-- Include jQuery from CDN (place this in your HTML head) -->
    <script src="https://code.jquery.com/jquery-3.6.4.min.js"></script>
  2. HTML Structure: Assuming you have a password input field and a button for toggling, create the following structure:

    <div class="password-container">
       <input type="password" id="password" name="password" placeholder="Password">
       <button type="button" id="togglePassword">Show/Hide</button>
    </div>
  3. JavaScript/jQuery: Add the following JavaScript/jQuery code to toggle the password visibility:

    <script>
       $(document).ready(function() {
           $("#togglePassword").on("click", function() {
               var passwordField = $("#password");
               var passwordFieldType = passwordField.attr("type");
               passwordField.attr("type", passwordFieldType === "password" ? "text" : "password");
           });
       });
    </script>

    This script listens for a click event on the "Show/Hide" button and toggles the password input field's type attribute between "password" and "text."

Adjust the IDs and classes according to your specific HTML structure.

By implementing this approach, users will be able to show/hide the password in the password input field by clicking the designated button.

pxpm commented 6 months ago

Thanks for the tip @horgolzari98 . ChatGPT got it "almost" right. 😍

Indeed @karandatwani92 I don't see why we wouldn't add that functionality to the password field too.

Very good suggestion and catch. 🙏