将 '.error' class 绑定到手动创建的 haml 包装器

Bind '.error' class to manually created haml wrapper

我有下一组控件:

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

是否有任何方法可以将“.control-group”绑定到它的子输入,因此如果输入无效,包装器将添加 class“.error”?

谢谢

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

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'}",但是在包装器配置中处理这种情况会很棒。就像如果类型是 'email' - 然后插入类型 'text'.