ErrorTag
A component inspired by error_tag/3
that ships with mix phx.new
in
MyAppWeb.ErrorHelpers
Renders error messages if any exist regarding the given field.
Error Translation
Changeset errors are translated using the default error translator
that ships with phoenix when generated with mix phx.new --no-gettext
.
When using Gettext, you can use configuration to route all errors through
the MyAppWeb.ErrorHelpers.translate_error/1
function generated by Phoenix,
which utilizes Gettext
. You need to provide a tuple with the module and
the name of the function (as an atom) as follows:
config :surface, :components, [
{Surface.Components.Form.ErrorTag, default_translator: {MyAppWeb.ErrorHelpers, :translate_error}}
]
Note: If you don't configure a
default_translator
, Surface will try to translate errors using a built-in message translator which may not cover all types of errors. If the error cannot be translated, a generic"invalid value"
will be returned and a warning will be emitted, reminding the user to set up a properdefault_translator
that can handle such cases.
There is also a translator
prop which can be used on a case-by-case basis.
It overrides the configuration.