【问题标题】:SimpleForm w. Bootstrap - Input changes to "form-inline" when setting "html5: true"SimpleForm w。 Bootstrap - 设置“html5:true”时输入更改为“form-inline”
【发布时间】:2017-09-28 01:51:52
【问题描述】:

我有一个基于时间的输入,我想将其显示为一个输入与两个默认选择框。我发现解决方案是将html: true 添加到我的输入中。不幸的是,这会将输入的父容器类从form-control 更改为form-inline。有没有办法在 SimpleForm 中改变这一点,而无需在 html 选项哈希中明确地给它类?

【问题讨论】:

    标签: ruby-on-rails twitter-bootstrap simple-form


    【解决方案1】:

    转到 simple_form_bootstrap.rb 并检查此片段

    config.wrappers :multi_select, tag: :div, class: 'form-group', error_class: 'has-danger' do |b|
        b.use :html5
        b.optional :readonly
        b.use :label
        b.wrapper tag: :div, class: 'form-inline' do |ba|
            ba.use :input, class: 'form-control'
            ba.use :error, wrap_with: { tag: :div, class: 'invalid-feedback' }
            ba.use :hint,  wrap_with: { tag: :small, class: 'form-text text-muted' }
        end
    end
    

    有您正在寻找的内联表单,请注意时间和日期的默认包装器是 multi_select

    config.wrapper_mappings = {
        check_boxes: :horizontal_radio_and_checkboxes,
        radio_buttons: :horizontal_radio_and_checkboxes,
        file: :horizontal_file_input,
        boolean: :horizontal_boolean,
        datetime: :multi_select,
        date: :multi_select,
        time: :multi_select
    }
    

    【讨论】:

    • 顺便说一下,这是我的配置之一,所以可能会有一些差异。
    • 我的确实看起来一样。我会简单地从哈希中删除键/值对,还是有一个值可以让它显示为一个输入?
    • 您可以将 form-inline 更改为您想要的并保持 de html true 选项或创建自定义包装器并将其设置为 f.input :date, wrapper: :my_custom_wrapper
    • 正确。谢谢!
    猜你喜欢
    • 2014-07-21
    • 2014-03-20
    • 1970-01-01
    • 2014-04-10
    • 1970-01-01
    • 2018-02-20
    • 1970-01-01
    • 2014-08-20
    • 1970-01-01
    相关资源
    最近更新 更多