Ash FrameworkAF
Ash Frameworkβ€’2mo agoβ€’
16 replies
Shawn McCool

No HTML5 Form Validation for Actions / Dead view form errors missing?

I'm experimenting with forms with the following code using out-of-the-box Ash / Ash Authentication / Ash Phoenix mixed with traditional non-liveview controllers. I expected that AshPhoenix would generate HTML5 validation on the form, because this is the kind of thing I'd think Ash was good at. But it doesn't seem to be the case. Is it possible I'm implementing it incorrectly?

# default User resource change_password action
update :change_password do
  # Use this action to allow users to change their password by providing
  # their current password and a new password.

  require_atomic? false
  accept []
  argument :current_password, :string, sensitive?: true, allow_nil?: false

  argument :password, :string,
    sensitive?: true,
    allow_nil?: false,
    constraints: [min_length: 8]

  argument :password_confirmation, :string, sensitive?: true, allow_nil?: false

  validate confirm(:password, :password_confirmation)

  validate {AshAuthentication.Strategy.Password.PasswordValidation,
            strategy_name: :password, password_argument: :current_password}

  change {AshAuthentication.Strategy.Password.HashPasswordChange, strategy_name: :password}
end

# controller
def change_password_form(conn, _params) do
  user = conn.assigns[:current_user]

  form =
    AshPhoenix.Form.for_update(user, :change_password, as: "user", actor: user)
    |> to_form()

  conn
  |> render(:change_password_form, form: form)
end

# template
<.form
  for={@form}
  id="change-password-form"
  action={~p"/settings/change-password"}
  method="post"
>
  <.input field={@form[:current_password]} type="password" label="Current Password" />
  <.input field={@form[:password]} type="password" label="New Password" />
  <.input field={@form[:password_confirmation]} type="password" label="Confirm New Password" />
  <.button>Change Password</.button>
</.form>
Was this page helpful?