How to remove label prefix in errors

Viewed 11

How do I remove the prefix that is added to errors?

For example, given this error:

activerecord:
  errors:
    models:
      my_model:
        my_custom_error: Incorrect value

I'd like the input to show the error as exactly "Incorrect value". But instead SimpleForm always adds the name of the attribute as a prefix. So it shows as "my_custom_error Incorrect value".

How can I remove the prefix for some inputs?

Seems like the prefix is added here: https://github.com/heartcombo/simple_form/blob/main/lib/simple_form/components/errors.rb#L30

1 Answers

The label + message format comes from this I18n:

errors:
    format: "%{attribute} %{message}"

So you need to redefine it to:

errors:
    format: "%{message}"
Related