在 RefineryCMS 中重写 ActionView::Base.field_error_proc
我试图在我的refineryCMS 应用程序中使用 client_side_validations gem (https://github.com/bcardarella/client_side_validations) 来内联显示客户端验证错误。
当我跳出无效字段时,它会按预期包装在 span.fieldWithErrors 标记中,因此我知道 javascript 验证正在工作。但是,即使在覆盖 ActionView::Base.field_error_proc 之后,我也无法显示错误消息。
我有一种感觉,我的初始化程序随后被精炼厂覆盖(?):
在 config/initializers/client_side_validations.rb 中:
# Uncomment the following block if you want each input field to have the validation messages attached.
ActionView::Base.field_error_proc = Proc.new do |html_tag, instance|
unless html_tag =~ /^<label/
%{<div class="field_with_errors">#{html_tag}<label for="#{instance.send(:tag_id)}" class="message">#{instance.error_message.first}</label></div>}.html_safe
else
%{<div class="field_with_errors">#{html_tag}</div>}.html_safe
end
end
内容从 config/application.rb 设置 field_error_proc :
config.action_view.field_error_proc = Proc.new { |html_tag, instance| # etc... }
我还尝试使用以下 对渲染无效字段有任何影响。有什么想法吗?
I'm trying to have client-side validation errors show up inline, using the client_side_validations gem (https://github.com/bcardarella/client_side_validations) in my refineryCMS app.
When I tab out of an invalid field, it gets wrapped in a span.fieldWithErrors tag, as expected, so I know that the javascript validations are working. However, I am unable to have the error messages show up, even after overriding ActionView::Base.field_error_proc.
I have a feeling that my initializer is being subsequently overridden by refinery (?):
In config/initializers/client_side_validations.rb:
# Uncomment the following block if you want each input field to have the validation messages attached.
ActionView::Base.field_error_proc = Proc.new do |html_tag, instance|
unless html_tag =~ /^<label/
%{<div class="field_with_errors">#{html_tag}<label for="#{instance.send(:tag_id)}" class="message">#{instance.error_message.first}</label></div>}.html_safe
else
%{<div class="field_with_errors">#{html_tag}</div>}.html_safe
end
end
I have also tried setting the field_error_proc from config/application.rb using something along the lines of
config.action_view.field_error_proc = Proc.new { |html_tag, instance| # etc... }
Neither of these seem to have any effect on the rendering invalid fields. Any ideas??
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
事实证明,refineryCMS 确实覆盖了 field_error_proc:
https://github.com/refinery/refinerycms/issues/961
这对我有用:
Turns out refineryCMS does indeed override field_error_proc:
https://github.com/refinery/refinerycms/issues/961
This worked for me: