如何解决是否可以覆盖 SimpleForm 生成的表单字段的基“类”?
这是我的simple_form.rb
:
config.wrappers :select_form,tag: "div",class: "control" do |b|
b.use :html5
b.use :placeholder
b.optional :pattern
b.optional :readonly
b.use :label,class: "label"
b.use :input,wrap_with: { tag: "div",class: "select" }
b.use :full_error,class: "help is-danger" }
b.use :hint,wrap_with: { tag: "small",class: "form-text text-muted" }
end
产生这个:
<div class="control select required user_role"><label class="label select required" for="user_role">User Role</label>
<div class="select"><select class="select required" required="required" aria-required="true" name="user[role]" id="user_role">
问题是 SimpleForm 和我的 CSS 类 Bulma 都使用 .select
类来确定元素的类型,从而导致图形冲突。
是否有必要从父类 select
中删除类 <div>
,因为它没有必要?
解决方法
将此添加到我的 initializers/simple_form.rb
中:
class SimpleForm::Wrappers::Many
def wrap(input,options,content)
return content if options[namespace] == false
return if defaults[:unless_blank] && content.empty?
tag = (namespace && options[:"#{namespace}_tag"]) || @defaults[:tag]
return content unless tag
klass = html_classes(input,options)
opts = html_options(options)
# Removes the conflict class ".select" from the wrapper
klass.delete(:select) if options[:wrapper] == :select_form && klass.length > 1
opts[:class] = (klass << opts[:class]).join(' ').strip unless klass.empty?
input.template.content_tag(tag,content,opts)
end
end
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。