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

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

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

这是我的代码

  1. <%= 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部分默认包装器:
  1. b.use :label_input
  2. b.use :hint,wrap_with: { tag: :span,class: :hint }
  3. b.use :error,class: :error }

至:

  1. b.use :label
  2. b.use :hint,class: :error }
  3. b.use :input

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

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

  1. config.wrappers :checks,class: :input,hint_class: :field_with_hint,error_class: :field_with_errors do |b|
  2. b.use :html5
  3. b.use :placeholder
  4. b.optional :maxlength
  5. b.optional :pattern
  6. b.optional :min_max
  7. b.optional :readonly
  8.  
  9. ## Inputs
  10. b.use :label_input
  11. b.use :hint,class: :hint }
  12. b.use :error,class: :error }
  13. end
  14. config.wrapper_mappings = { boolean: :checks }

猜你在找的Ruby相关文章