fixing error tag ids problem in liveview, and activating stricter password requirements
This commit is contained in:
parent
a151bfcee7
commit
73c97f194b
9 changed files with 56 additions and 1038 deletions
lib/shift73k_web
live
user
user_management
views
|
@ -22,7 +22,7 @@
|
|||
maxlength: User.max_email,
|
||||
autofocus: true,
|
||||
phx_debounce: "blur",
|
||||
aria_describedby: error_id(f, :email)
|
||||
aria_describedby: error_ids(f, :email)
|
||||
%>
|
||||
<%= error_tag f, :email %>
|
||||
</div>
|
||||
|
@ -39,7 +39,7 @@
|
|||
class: input_class(f, :password, "form-control"),
|
||||
maxlength: User.max_password,
|
||||
phx_debounce: "250",
|
||||
aria_describedby: error_id(f, :password)
|
||||
aria_describedby: error_ids(f, :password)
|
||||
%>
|
||||
<%= error_tag f, :password %>
|
||||
</div>
|
||||
|
|
|
@ -20,7 +20,7 @@
|
|||
class: input_class(f, :password, "form-control"),
|
||||
maxlength: User.max_password,
|
||||
autofocus: true,
|
||||
aria_describedby: error_id(f, :password)
|
||||
aria_describedby: error_ids(f, :password)
|
||||
%>
|
||||
<%= error_tag f, :password %>
|
||||
</div>
|
||||
|
@ -36,7 +36,7 @@
|
|||
value: input_value(f, :password_confirmation),
|
||||
class: input_class(f, :password_confirmation, "form-control"),
|
||||
maxlength: User.max_password,
|
||||
aria_describedby: error_id(f, :password_confirmation)
|
||||
aria_describedby: error_ids(f, :password_confirmation)
|
||||
%>
|
||||
<%= error_tag f, :password_confirmation %>
|
||||
</div>
|
||||
|
|
|
@ -16,7 +16,7 @@
|
|||
placeholder: "e.g., babka@73k.us",
|
||||
maxlength: User.max_email,
|
||||
phx_debounce: "500",
|
||||
aria_describedby: error_id(f, :email)
|
||||
aria_describedby: error_ids(f, :email)
|
||||
%>
|
||||
<%= error_tag f, :email %>
|
||||
</div>
|
||||
|
@ -32,7 +32,7 @@
|
|||
<%= password_input f, :current_password,
|
||||
value: input_value(f, :current_password),
|
||||
class: "form-control",
|
||||
aria_describedby: error_id(f, :current_password)
|
||||
aria_describedby: error_ids(f, :current_password)
|
||||
%>
|
||||
<%= error_tag f, :current_password %>
|
||||
</div>
|
||||
|
|
|
@ -15,7 +15,7 @@
|
|||
class: input_class(f, :password, "form-control"),
|
||||
maxlength: User.max_password,
|
||||
phx_debounce: "500",
|
||||
aria_describedby: error_id(f, :password)
|
||||
aria_describedby: error_ids(f, :password)
|
||||
%>
|
||||
<%= error_tag f, :password %>
|
||||
</div>
|
||||
|
@ -31,7 +31,7 @@
|
|||
value: input_value(f, :password_confirmation),
|
||||
class: input_class(f, :password_confirmation, "form-control"),
|
||||
maxlength: User.max_password,
|
||||
aria_describedby: error_id(f, :password_confirmation)
|
||||
aria_describedby: error_ids(f, :password_confirmation)
|
||||
%>
|
||||
<%= error_tag f, :password_confirmation %>
|
||||
</div>
|
||||
|
@ -46,7 +46,7 @@
|
|||
<%= password_input f, :current_password,
|
||||
value: input_value(f, :current_password),
|
||||
class: "form-control",
|
||||
aria_describedby: error_id(f, :current_password)
|
||||
aria_describedby: error_ids(f, :current_password)
|
||||
%>
|
||||
<%= error_tag f, :current_password %>
|
||||
</div>
|
||||
|
|
|
@ -19,7 +19,7 @@
|
|||
maxlength: User.max_email,
|
||||
autofocus: true,
|
||||
phx_debounce: "250",
|
||||
aria_describedby: error_id(f, :email)
|
||||
aria_describedby: error_ids(f, :email)
|
||||
%>
|
||||
<%= error_tag f, :email %>
|
||||
</div>
|
||||
|
@ -50,7 +50,7 @@
|
|||
value: input_value(f, :password),
|
||||
class: input_class(f, :password, "form-control"),
|
||||
maxlength: User.max_password,
|
||||
aria_describedby: error_id(f, :password)
|
||||
aria_describedby: error_ids(f, :password)
|
||||
%>
|
||||
<%= error_tag f, :password %>
|
||||
</div>
|
||||
|
|
|
@ -8,26 +8,41 @@ defmodule Shift73kWeb.ErrorHelpers do
|
|||
@doc """
|
||||
Generates tag for inlined form input errors.
|
||||
"""
|
||||
def error_tag(form, field, opts \\ []) do
|
||||
opts = error_opts(form, field, opts)
|
||||
def error_tag(%Phoenix.HTML.Form{} = form, field, opts \\ []) do
|
||||
opts = error_common_opts(form, field, "invalid-feedback", opts)
|
||||
|
||||
form.errors
|
||||
|> Keyword.get_values(field)
|
||||
|> Enum.map(fn error -> content_tag(:span, translate_error(error), opts) end)
|
||||
|> Stream.with_index()
|
||||
|> Enum.map(fn err_with_index -> error_tag_span(err_with_index, opts) end)
|
||||
end
|
||||
|
||||
defp error_opts(form, field, opts) do
|
||||
append = "invalid-feedback"
|
||||
input_id = input_id(form, field)
|
||||
defp error_tag_span({err, _} = err_with_index, opts) do
|
||||
opts = error_tag_opts(err_with_index, opts)
|
||||
content_tag(:span, translate_error(err), opts)
|
||||
end
|
||||
|
||||
opts
|
||||
|> Keyword.put_new(:id, error_id(input_id))
|
||||
|> Keyword.put_new(:phx_feedback_for, input_id)
|
||||
|
||||
defp error_common_opts(form, field, append, opts) do
|
||||
Keyword.put(opts, :phx_feedback_for, input_id(form, field))
|
||||
|> Keyword.update(:class, append, fn c -> "#{append} #{c}" end)
|
||||
end
|
||||
|
||||
def error_id(%Phoenix.HTML.Form{} = form, field), do: input_id(form, field) |> error_id()
|
||||
def error_id(input_id) when is_binary(input_id), do: "#{input_id}_feedback"
|
||||
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))
|
||||
end
|
||||
|
||||
defp error_id(input_id, err_index), do: "#{input_id}_feedback-#{err_index}"
|
||||
|
||||
def error_ids(%Phoenix.HTML.Form{} = form, field) do
|
||||
input_id = input_id(form, field)
|
||||
form.errors
|
||||
|> Keyword.get_values(field)
|
||||
|> Stream.with_index()
|
||||
|> Stream.map(fn {_, index} -> error_id(input_id, index) end)
|
||||
|> Enum.join(" ")
|
||||
end
|
||||
|
||||
def input_class(form, field, classes \\ "") do
|
||||
case form.source.action do
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue