首页 > 解决方案 > 如何在简单表单中设置内联标签的样式?

问题描述

我有一个简单表单复选框,它同时使用常规字段标签和内联标签:

<%= f.input :remove_default_template, 
  label: 'Advanced Option',
  inline_label: "Remove Header, Footer, and Department Name"
%>

我需要为内联标签添加样式。我怎样才能做到这一点?我希望遵循这种模式的东西可以工作:

<%= f.input :remove_default_template, 
  label: 'Advanced Option',
  inline_label: "Remove Header, Footer, and Department Name",
  inline_label_html: 
  input_html: {class: "input_class"},               # THIS works
  wrapper_html: {class: "wrapper_class"},           # THIS works
  label_html: {class: "label_class"},               # THIS works  
  inline_label_html: {class: "inline_label_class"}  # THIS DOES NOT WORK!!!
%>

但最后一行不起作用:

inline_label_html: {class: "inline_label_class"}

由于 Simple Form 似乎不支持此选项(至少以我期望的名称,也没有我能找到的任何其他名称),我怎样才能实现相同的目标?

标签: ruby-on-railsrubysimple-form

解决方案


您可能想要一个提示,而不是内联标签。

然后你可以写一个包装器,它允许做这样的事情

<%= f.input :subdomain, input_wrapper_html: { class: 'col-sm-4' } %>

然后你的提示将是内联的。

请在此处查看https://github.com/plataformatec/simple_form/issues/1035


推荐阅读