0

I have next group of controls:

.control-group.string.required.user_name
  = f.input_field :name, required: true, class: 'form-control'
  = f.label 'User Name'
  = f.error :name

Is there any way to bind '.control-group' to it's child input, so if input is invalid, wrapper will get class ".error" added?

Thanks

4

1 回答 1

0

我为此创建了一个自定义组件,如下所示

config.wrappers :perfect_forms, tag: 'div', class: 'control-group', required: true, error_class: 'error' do |b|
  b.use :html5
  b.use :input, class: 'fotm-control', required: true
  b.use :label
  b.use :error, wrap_with: { tag: 'span', class: 'help-inline' }
end

现在有一个问题,是否可以检测此配置中的输入类型?因为目前要明确设置输入的类型,所以我正在为所需的输入编写“input_html: { type: 'text'}”,但是在包装器配置中处理这种情况会很棒。就像类型是“电子邮件”一样 - 然后插入类型“文本”。

于 2015-06-17T14:25:27.903 回答