2016-03-04 47 views
2

我创建了issue on their github但我想问我这个社区,因为它倾向于simple_form宇宙的一小部分。simple_form工具提示组件在自举输入组包装没有显示

我已经成功地使用their wiki instructions添加了引导程序自定义包装。

我还通过以下these instructions向这些组件添加了工具提示助手。稍作修改以使用翻译文件。见下文。

但是,问题在于仅当没有使用input-group时,工具提示才起作用。看起来,包装上设置的属性不会传播到输入内部?

有没有其他人看过这个或得到这个?以下是重要的一点。

下面是我如何使用工具提示定义自定义包装。

config.wrappers :horizontal_input_group, tag: 'div', class: 'form-group', error_class: 'has-error' do |b| 
    b.use :html5 
    b.use :placeholder 
    b.use :label, class: 'col-sm-4 control-label' 
    b.use :tooltip 

    b.wrapper tag: 'div', class: 'col-sm-8' do |ba| 
    ba.wrapper tag: 'div', class: 'input-group col-sm-12' do |append| 
     append.use :input, class: 'form-control' 
    end 

    ba.use :error, wrap_with: { tag: 'span', class: 'help-block' } 
    ba.use :hint, wrap_with: { tag: 'p', class: 'help-block' } 
    end 
end 

这里是我如何在我的形式调用它。

= f.input :peak_visibility, wrapper: :horizontal_input_group, label: 'Peak Audience Visibility' do 
    = f.input_field :peak_visibility, class: 'form-control' 
    %span{class: 'input-group-addon'} % 

这里是我添加到simple-from的工具提示助手文件。

module SimpleForm 
    module Components 
    module Tooltips 
     def tooltip(wrapper_options = nil) 
     unless tooltip_text.nil? 
      input_html_options[:rel] ||= 'tooltip' 
      input_html_options['data-toggle'] ||= 'tooltip' 
      input_html_options['data-placement'] ||= tooltip_position 
      input_html_options['data-trigger'] ||= 'focus' 
      input_html_options['data-original-title'] ||= tooltip_text 
      nil 
     end 
     end 

     def tooltip_text 
     tooltip = options[:tooltip] 
     if tooltip.is_a?(String) 
      tooltip 
     elsif tooltip.is_a?(Array) 
      tooltip[1] 
     else 
      nil 
     end 
     end 

     def tooltip_position 
     tooltip = options[:tooltip] 
     tooltip.is_a?(Array) ? tooltip[0] : "right" 
     end 
    end 
    end 
end 

SimpleForm::Inputs::Base.send(:include, SimpleForm::Components::Tooltips) 

回答

-1

我没有使用twitter-bootstrap gem,但也许这可以帮助你。

在您的视图中为您的html输入和相应的脚本添加数据切换和标题。

例如:

<label data-original-title="Very Good" for="evaluation" data-toggle="tooltip" data-placement="bottom" title=""></label> 

<script type="text/javascript"> 
     $(document).ready(function(){ 
     $("[data-toggle='tooltip']").tooltip(); 
     }); 
</script> 

您还可以使用标签/输入轨数据和标题ARGS助手:

<%= f.label :evaluation, "Evaluation:", data: {toggle: "tooltip", placement: "bottom" }, title: "Very Good" %> 

又见this post为您服务!

+0

这似乎并没有解决这个问题,这是专门做这个轨道宝石如何输出的HTML。 –

+0

我更新了指定我没有使用宝石。 – aranhaqg