-
Notifications
You must be signed in to change notification settings - Fork 49
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Override reform full_messages to use ActiveModel full_messages #85
Conversation
Reform has its own full_messages implementation as we can see here https://github.com/trailblazer/reform/blob/master/lib/reform/errors.rb#L29 and reform-rails ResultErrors class inherits from Reform::Contract::Result::Errors, so when you call "full_messages" to get the full error messages, it was calling reform full_messages implementation instead of delegating to ActiveModel and this is a problem for whom need to translate attribute names, because reform only humanizes the attribute name. Fixes: #56
We iterate over each field and for fields which is value is a twin::collection we get the instance variable of @amv_errors and call full_messages which will return the full translated messages of the collection fields.
@apotonick @emaglio Could someone of you take a look on this? |
Wow! 😍 This looks very good! Can you remind me what the "original" Reform-version of |
The original behavior was that the reform full_messages was called instead delegated to ActiveModel Example, rails project -> en.yml activemodel:
attributes:
my_form:
name: User name my_form.rb validates :name, presence: true The original behavior would return the following error message |
Anything I could do to help this PR advance? It would be nice to be able to update the version of |
@marcelolx thanks for this! @valscion want to add some small extra specs but I'm going to release a new version for this gem between today and tomorrow 👍 |
|
Thanks @emaglio! I can verify that |
Reform has its own full_messages implementation as we can see here
https://github.com/trailblazer/reform/blob/master/lib/reform/errors.rb#L29
and reform-rails ResultErrors class inherits from
Reform::Contract::Result::Errors, so when you call "full_messages" to
get the full error messages, it was calling reform full_messages
implementation instead of delegating to ActiveModel and this is a
problem for whom need to translate attribute names, because reform only
humanizes the attribute name.
I've do some "hacks" to get the full error messages of collections/nested properties of the form, if there is another better way to get the full_messages from AM, I'm open to the possibilities.
Fixes: #56
Fixes: #83
If I'm missing anything, please let me know.