(Ruby on Rails) Issue Rendering Sign Up Page After Error Messages

I am new to Ruby on Rails and am trying to create a sign up page. I have a minor bug that occurs when a user enters invalid information in the form. I currently redirect them back to the sign up page and render the same page, except now including the error messages. The issue is that on the rerendered page the show password button does not work and the enter password field collapses (see picture 1). I am not understanding why these elements are changing since it is essentially the same page. Here is my html file for the page.

<!-- app/views/registrations/new.html.erb -->

<h1>Sign Up</h1>

<%= form_with model: @user, url: sign_up_path do |form| %>
  <% if @user.errors.any? %>
    <div class="alert alert-danger">
      <p>There were errors with your submission:</p>
      <ul>
        <% @user.errors.full_messages.each do |message| %>
          <li><%= message %></li>
        <% end %>
      </ul>
    </div>
  <% end %>

  <!-- Email input field -->
  <div class="mb-3">
    <%= form.label :email %>
    <%= form.text_field :email, class: "form-control", placeholder: "Enter your email" %>
  </div>

  <!-- Password input field with a toggle button to show/hide the password -->
  <div class="mb-3">
    <%= form.label :password %>
    <div class="input-group">
      <%= form.password_field :password, class: "form-control password-field", placeholder: "Enter your password", autocomplete: "new-password" %>
      <button type="button" class="btn btn-outline-secondary toggle-password" aria-label="Toggle password visibility">
        <i class="bi bi-eye"></i>
      </button>
    </div>
    <div id="passwordHelpBlock" class="form-text">
      Password must be at least 8 characters long and include at least one uppercase letter, one number, and one special character.
    </div>
  </div>


  <!-- Password confirmation input field -->
  <div class="mb-3">
    <%= form.label :password_confirmation %>
    <%= form.password_field :password_confirmation, class: "form-control", placeholder: "Confirm your password", autocomplete: "new-password" %>
  </div>

  <!-- Submit button -->
  <div class="actions">
    <%= form.submit "Sign Up", class: "btn btn-primary" %>
  </div>
<% end %>

<!-- JavaScript to toggle the visibility of the password field -->
<script>
  document.addEventListener("turbo:load", function() {
    const form = document.querySelector("form");

    form.addEventListener("click", function(event) {
      const togglePasswordButton = event.target.closest(".toggle-password");

      if (togglePasswordButton) {
        const passwordField = togglePasswordButton.closest(".mb-3").querySelector(".password-field");

        if (passwordField) {
          if (passwordField.type === "password") {
            passwordField.type = "text";
            togglePasswordButton.innerHTML = '<i class="bi bi-eye-slash"></i>';
          } else {
            passwordField.type = "password";
            togglePasswordButton.innerHTML = '<i class="bi bi-eye"></i>';
          }
        }
      }
    });
  });
</script>

I am expecting the password field to be the same length as the others and the show password button (left side of password field) to have functionality.

New contributor

Robert Stark is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật