Correct Display of Errors in Phoenix.HTML with Bootstrap

phoenix
errors
bootstrap

#1

Bootstrap requires since Bootstrap 4.0 is-invalid as field class to display the field error.
I found a solution presented in the following to display the errors again, but I don’t really know what’s the best way to integrate it. I add for each field with errors in a generic way the is_invalid class.

def password_input(form, field, opts \\ []) do
  opts = if !is_atom(form) && Keyword.has_key?(form.errors, field), do: Keyword.update(opts, :class, "is-invalid", &("#{&1} is-invalid")), else: opts
  ...

I wonder now how I can integrate this in the best way into the Phoenix.HTML helpers with touching them as least as possible, so I hopefully have the least trouble to stay up to date with the helpers.

In a way like this to just not import the functions I need to “override”?


#2

I haven’t tried it yet, but expect I’m going to be in the same boat as you with a side project I’m starting that is planned to use BS 4. There haven’t been updates to this in a while, but if the BS markup hasn’t changed, it may not need any.