Shouldn’t validate_confirmation only cause an error if the the changeset has a change for that field but not for the field_confirmation field?

It looks like it looks at the changeset params instead of changes source
If that doesn’t make sense, how would I require confirmation on a field but only if it’s changed? validate_change?
And if so, I feel like I’m reimplementing validate_confirmation :thinking_face:
I feel like it would make sense to work similar to how validate_format works, it only cares about the format for a change not the params

1 Like

You could conditionally add validate_confirmation

def changeset(data, params) do
   |> cast(params, [:field])
   |> confirm_if_field_is_different(params)

def confirm_if_field_is_different(changeset, params) do
  # .... compare stuff
  case is_different do
    true -> validate_confirmation(changeset, :field)
     _ -> changeset
1 Like

I feel like the API is wrong though, most of the other validations act on changes, I’m not sure why this one is different?

1 Like