simple_form提示为工具提示

时间:2014-07-07 10:00:45

标签: javascript css twitter-bootstrap simple-form

我尝试将simple_form提示显示为twitter-bootstrap工具提示,以便只有当用户选择输入字段或悬停在其上时才会显示提示。

表单项看起来像(以haml为单位):

:ruby 
  title = <<TITLE
    This text is normally hidden and pops up as a bootstrap tooltip 
    only when the user hovers on the input field.
  TITLE
= f.input :opt_out, hint: title 

我的CSS和Javascript提示simple_form是vanilla,所以我想我必须修改config/initializers/simple_form.rb初始化文件:

b.use :hint,  :wrap_with => { :tag => :span, :class => :hint }

1 个答案:

答案 0 :(得分:1)

我用这种方式解决了它:

    :ruby 
      title = <<TIT 
        This text is normally hidden and pops up as a bootstrap tooltip 
only when the user hovers on the input field.
      TIT
      link = link_to "what's this?", "", rel: "tooltip", title: title, data: {placement: "right"}
      label = "Opt out #{link}"
    = f.input :opt_out, label: raw(label)