ruby-on-rails – Rails simple_form,在输入之前移动提示

前端之家收集整理的这篇文章主要介绍了ruby-on-rails – Rails simple_form,在输入之前移动提示前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
无论如何移动提示组件使其出现在输入之前?

当前显示的组件按以下顺序显示标签,输入,提示,错误.我尝试添加:components选项,但这不起作用.

这是我的代码

<%= f.input :content,:components => [:label,:hint,:input],:as => :text,hint: 'Please 1) include your exact copy here,2) upload your copy document in the next step,or 3) describe any content services to include in our estimate.',required: true,:label => "Copy" %>

解决方法

您可以在以下位置修改config / initializers / simple_form.rb中的Inputs部分默认包装器:
b.use :label_input
b.use :hint,wrap_with: { tag: :span,class: :hint }
b.use :error,class: :error }

至:

b.use :label
b.use :hint,class: :error }
b.use :input

本节从默认生成的simple_form.rb的第42行开始

这将使单个复选框在出现错误时看起来有点奇怪,因此您还需要创建一个与原始配置重复的包装器版本,并将其设置为仅用于布尔输入类型.例如:

config.wrappers :checks,class: :input,hint_class: :field_with_hint,error_class: :field_with_errors do |b|
    b.use :html5
    b.use :placeholder
    b.optional :maxlength
    b.optional :pattern
    b.optional :min_max
    b.optional :readonly

    ## Inputs
    b.use :label_input
    b.use :hint,class: :hint }
    b.use :error,class: :error }
end
config.wrapper_mappings = { boolean: :checks }
原文链接:https://www.f2er.com/ruby/267592.html

猜你在找的Ruby相关文章