Skip to content

Commit

Permalink
Only show password validation errors in password change form
Browse files Browse the repository at this point in the history
We're about to add another form to this page to allow the user to
change their email. Since that form will also act on the User model we
want to make sure that the relevant validation errors are shown on
each form. This form deals with errors on the password field so we add
a guard clause for those.
  • Loading branch information
chrislo committed Oct 29, 2024
1 parent e9e8373 commit 7923cc2
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion app/views/users/show.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@
<% if flash[:incorrect_password] %>
<%= render ErrorBoxComponent.new(title: 'Incorrect password').with_content(flash[:incorrect_password]) %>
<% end %>
<%= render ModelErrorComponent.new(model: @user) %>
<% if @user.errors.include?(:password) %>
<%= render ModelErrorComponent.new(model: @user) %>
<% end %>
<%= form.password_field :current_password, required: true, autofocus: true, autocomplete: "current-password", class: "w-full mb-3" %>
<%= form.password_field :password, label: { text: "New password"}, required: true, autocomplete: "new-password", class: "w-full mb-3" %>
<%= form.password_field :password_confirmation, label: { text: "Confirm new password"}, required: true, autocomplete: "new-password", class: "w-full mb-3" %>
Expand Down

0 comments on commit 7923cc2

Please sign in to comment.