如何在 simple_form gem 中使用 Bootstrap 的输入组 [英] How to use Bootstrap's input group in simple_form gem

查看:61
本文介绍了如何在 simple_form gem 中使用 Bootstrap 的输入组的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

环境

  • Ruby 2.5.1
  • Rails 5.2.1
  • 简单表格 4.0.1

当前行为

我遵循 http://simple-form-b​​ootstrap.plataformatec 中的示例.com.br/examples/input_group

我从 <%= simple_form_for app, wrapper: :input_group do |f| 开始%> 并得到 Couldn't find wrapper with name input_group,所以我取消注释

config.wrappers :input_group, tag: 'div', class: 'form-group', error_class: 'form-group-invalid', valid_class: 'form-group-valid' do |b|b.使用:html5b.使用:占位符b.可选:最大长度b.可选:最小长度b.可选:模式b.可选:min_maxb.可选:只读b.use :label, class: 'form-control-label'b.wrapper :input_group_tag, tag: 'div', class: 'input-group' do |ba|ba.optional : 前置ba.use :input, class: 'form-control', error_class: 'is-invalid', valid_class: 'is-valid'ba.optional :append结尾b.use :full_error, wrap_with: { tag: 'div', class: 'invalid-feedback d-block' }b.use :hint, wrap_with: { tag: 'small', class: 'form-text text-muted' }结尾

simple_form_bootstrap.rb

并为 SimpleForm::Inputs::StringInput' 类获取 undefined methodappend' 代替.

关于这个 <%= f.input :subdomain, append: "example.com" %>

的问题

我如何使用它,它甚至支持 simple_form 吗?不知道他们为什么要注释掉那段代码.

解决方案

create config/initializers/simple_form_component.rb

模块输入组def prepend(wrapper_options = nil)span_tag = content_tag(:span, options[:prepend], class: "input-group-text")template.content_tag(:div, span_tag, class: "input-group-prepend")结尾def append(wrapper_options = nil)span_tag = content_tag(:span, options[:append], class: "input-group-text")template.content_tag(:div, span_tag, class: "input-group-append")结尾结尾# 以简单形式注册组件.SimpleForm.include_component(InputGroup)

来源

Environment

  • Ruby 2.5.1
  • Rails 5.2.1
  • Simple Form 4.0.1

Current behavior

I follow example in http://simple-form-bootstrap.plataformatec.com.br/examples/input_group

I start with <%= simple_form_for app, wrapper: :input_group do |f| %> and get Couldn't find wrapper with name input_group, so I uncomment

config.wrappers :input_group, tag: 'div', class: 'form-group', error_class: 'form-group-invalid', valid_class: 'form-group-valid' do |b|
    b.use :html5
    b.use :placeholder
    b.optional :maxlength
    b.optional :minlength
    b.optional :pattern
    b.optional :min_max
    b.optional :readonly
    b.use :label, class: 'form-control-label'
    b.wrapper :input_group_tag, tag: 'div', class: 'input-group' do |ba|
      ba.optional :prepend
      ba.use :input, class: 'form-control', error_class: 'is-invalid', valid_class: 'is-valid'
      ba.optional :append
    end
    b.use :full_error, wrap_with: { tag: 'div', class: 'invalid-feedback d-block' }
    b.use :hint, wrap_with: { tag: 'small', class: 'form-text text-muted' }
  end

in simple_form_bootstrap.rb

And get undefined methodappend' for class SimpleForm::Inputs::StringInput' instead.

Problem on this <%= f.input :subdomain, append: "example.com" %>

How can I use this, does this even support in simple_form? Don't know why they comment that chunk of code out.

解决方案

create config/initializers/simple_form_component.rb

module InputGroup
  def prepend(wrapper_options = nil)
    span_tag = content_tag(:span, options[:prepend], class: "input-group-text")
    template.content_tag(:div, span_tag, class: "input-group-prepend")
  end

  def append(wrapper_options = nil)
    span_tag = content_tag(:span, options[:append], class: "input-group-text")
    template.content_tag(:div, span_tag, class: "input-group-append")
  end
end

# Register the component in Simple Form.
SimpleForm.include_component(InputGroup)

Source

这篇关于如何在 simple_form gem 中使用 Bootstrap 的输入组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆