以下代码给出了“项目地址”标签:
%h2 New Project
= simple_form_for(@project, html: {class: "form-horizontal"}, wrapper: :horizontal_form) do |f|
= f.error_notification
= f.input :project_address, required: true
= f.button :submit, "Create"
除了使用f.label
之外,有没有办法制作标签标题案例(“项目地址”)?
答案 0 :(得分:3)
如果您想为所有标签添加标题,您可以在初始化程序中配置简单表单:
h1, h2 {
background-image: linear-gradient(to top, transparent 0px, transparent .15em, red .15em, red calc(.15em + 1px), transparent calc(.15em + 1px), transparent 100%);
text-shadow: 0px -2px 3px white, 0px -2px 3px white, 0px -2px 3px white, 0px -2px 3px white, 0px -2px 3px white, 0px -2px 3px white;
}
除非您使用# config/initializers/simple_form.rb
# How the label text should be generated altogether with the required text.
config.label_text = lambda { |label, required, explicit_label| "#{required} #{explicit_label ? label : label.to_s.titleize}" }
选项明确指定标签,否则这将使您的所有标签都成为标题。