Css 垂直简单形式的错误
我在我的RubyonRails项目中使用了simple_form gem和bootstrap。在垂直形式中,当显示带有错误的帮助块时,我有如下内容: 如何修复CSS中的帮助块类,将错误名称移到整行的底部,而不增加图标 这是我的一份火腿:Css 垂直简单形式的错误,css,ruby-on-rails,twitter-bootstrap,haml,simple-form,Css,Ruby On Rails,Twitter Bootstrap,Haml,Simple Form,我在我的RubyonRails项目中使用了simple_form gem和bootstrap。在垂直形式中,当显示带有错误的帮助块时,我有如下内容: 如何修复CSS中的帮助块类,将错误名称移到整行的底部,而不增加图标 这是我的一份火腿: .form-group.input-group %span.input-group-addon %i.fa.fa-lock = f.input :password, label: false, placeholde
.form-group.input-group
%span.input-group-addon
%i.fa.fa-lock
= f.input :password, label: false, placeholder: 'Type password'
可以通过修改simple_form配置文件中的默认包装器来实现这一点。使用默认(非引导)配置执行此操作的方法是在
config/initializers/simple_form.rb
中修改输入部分default wrapper,从:
b.use :label_input
b.use :hint, wrap_with: { tag: :span, class: :hint }
b.use :error, wrap_with: { tag: :span, class: :error }
致:
您可以对配置的引导版本应用相同的技术
这将使单个复选框出现错误时看起来有点奇怪,因此您还需要制作一个与原始配置重复的包装器版本,并将其设置为仅用于布尔输入类型。例如(同样来自默认配置,而不是引导配置):
b.use :label
b.use :hint, wrap_with: { tag: :span, class: :hint }
b.use :error, wrap_with: { tag: :span, class: :error }
b.use :input
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, wrap_with: { tag: :span, class: :hint }
b.use :error, wrap_with: { tag: :span, class: :error }
end
config.wrapper_mappings = { boolean: :checks }