fixing duplicate input element id issue

This commit is contained in:
Adam Piontek 2021-03-09 10:48:02 -05:00
parent ed2e7ac7c7
commit 4a367a6de6
3 changed files with 8 additions and 10 deletions

View file

@ -19,14 +19,13 @@
</div>
<%= label f, :current_password, class: "form-label" %>
<div class="inner-addon left-addon mb-3" phx-feedback-for="<%= input_id(f, :current_password) %>">
<div class="inner-addon left-addon mb-3">
<%= icon_div @socket, "bi-lock", [class: "icon is-left text-muted fs-5"] %>
<%= password_input f, :current_password,
value: input_value(f, :current_password),
class: "form-control",
aria_describedby: error_ids(f, :current_password)
id: "user_email_current_password",
class: "form-control"
%>
<%= error_tag f, :current_password %>
</div>
<div class="mb-3">

View file

@ -30,14 +30,13 @@
</div>
<%= label f, :current_password, class: "form-label" %>
<div class="inner-addon left-addon mb-3" phx-feedback-for="<%= input_id(f, :current_password) %>">
<div class="inner-addon left-addon mb-3">
<%= icon_div @socket, "bi-lock", [class: "icon is-left text-muted fs-5"] %>
<%= password_input f, :current_password,
value: input_value(f, :current_password),
class: "form-control",
aria_describedby: error_ids(f, :current_password)
id: "user_password_current_password",
class: "form-control"
%>
<%= error_tag f, :current_password %>
</div>
<div class="mb-3">

View file

@ -23,13 +23,13 @@ defmodule Bones73kWeb.ErrorHelpers do
end
defp error_common_opts(form, field, append, opts) do
Keyword.put(opts, :phx_feedback_for, input_id(form, field))
Keyword.put_new(opts, :phx_feedback_for, input_id(form, field))
|> Keyword.update(:class, append, fn c -> "#{append} #{c}" end)
end
defp error_tag_opts({_err, err_index}, opts) do
input_id = Keyword.get(opts, :phx_feedback_for, "")
Keyword.put(opts, :id, error_id(input_id, err_index))
Keyword.put_new(opts, :id, error_id(input_id, err_index))
end
defp error_id(input_id, err_index), do: "#{input_id}_feedback-#{err_index}"