-
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
fieldnames in error messages not found via i18n scope #83
Comments
Yeah, we've got the same issue. Seems like changes done in #44 have caused this, I think it might be due to how reform-rails/lib/reform/form/active_model/validations.rb Lines 119 to 122 in c78a70f
"not sure this is 100% compatible with AMV::Errors?" comment would point to to this direction, in that overriding The controller with bad translations showing up is fairly simple (authorization code removed from here): # frozen_string_literal: true
module API
module Catering
class InquiriesController < ApplicationController
def update
catering_inquiry = ::Catering::Inquiry.find(params[:id])
form = ::Catering::UpdateInquiryForm.new(catering_inquiry)
if form.validate(params[:inquiry])
form.sync
form.model.save!
respond_to do |format|
format.json { render(json: { success: true }) }
end
else
respond_to do |format|
format.json do
render(
json: { message: form.errors.full_messages.to_sentence },
status: :unprocessable_entity
)
end
end
end
end
end
end
end and the form itself is also fairly simple: # frozen_string_literal: true
module Catering
class UpdateInquiryForm < Reform::Form
model :inquiry
property :company, from: :author_company
property :author_name
property :event_at, type: Types::Form::Date
property :status
property :rent_fee, type: Types::Form::Float
property :catering_fee, type: Types::Form::Float
property :other_fees, type: Types::Form::Float
validates :status, inclusion: { in: Catering::Inquiry.statuses }
validates :author_name, presence: true
validates :event_at, presence: true, date: true
end
end It seems like this translation isn't getting applied like it did in fi:
attributes:
author_name: Asiakkaan nimi Proof that it worked in |
We've this problem too, i send a PR only overriding full_messages to reform-rails delegate the call to AM #85, but this doesn't solves the problem for nested model attributes, also I haven't looked at the comment on the code which @valscion highlighted, tomorrow I will take another look to see if that could be handled changing |
Yeah, we can test it :) — a few little things are currently in progress so we might not be able to get to it today already, but hopefully we'll get to testing it during this working week still. |
Based on a quick test #85 would seem to work For reference, here's the same page with |
@valscion Thanks for the tests ❤️ |
first: thanks for the update and everybodys work!
I dont know if this ticket belongs here or in the reform main gem, but since i am using ActiveRecord validations i suppose this is right here.
With reform-rails ( v0.2.0 + reform v2.3.1) using model.errors.full_messages the fieldnames with errors are not found within their 'normal' i18n scope which is either de.attributes.a_name or de.activerecord.attributes.my_model.a_name
it seems as if the method here needs to be overridden to make an i18n lookup instead of a simple capitalize https://github.com/trailblazer/reform/blob/master/lib/reform/errors.rb#L29
Does anybody else has this problem? I would probalby go with a monkey patch as a quick solution but this does not feel right.
The text was updated successfully, but these errors were encountered: