不包括使用field_with_errors的css div为使用f.text_field创建的字段,但适用于f.input [英] Not wrapping css div with field_with_errors for fields created with f.text_field but works for f.input

查看:224
本文介绍了不包括使用field_with_errors的css div为使用f.text_field创建的字段,但适用于f.input的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的观看次数有问题。我使用zurb基础的样式表,当我输入错误的输入形式我得到错误上面的形式,但包含错误的字段不包裹红色。进一步看,对于输入字段没有field_with_errors div包装器。在进一步深入这之后,我发现如果我使用f.input而不是f.text_field我得到正确的错误包装。

I'm having problems with my views. I'm using zurb foundation for stylesheets and when I enter wrong input in forms I get the error above the form but the fields containing the errors are not wrapped with red. Looking further into this there is no field_with_errors div wrapper for the input fields. After looking further into this I found out if I use f.input instead of f.text_field I get the correct error wrapping.

由于zurb有text_field,text_area等样式。我使用那些,但我没有得到错误的div从rails。有没有什么好的解决方案?

As zurb has styles for text_field, text_area etc. I'm using those but I don't get the error div from rails. Is there any good solution to this?

这里我得到正确的Zurb基础造型,但没有field_with_errors div:

Here I get correct Zurb foundation styling but no field_with_errors div:

.field
  = f.label :name
  = f.text_field :name, :class => "input-text"

这里我没有得到Zurb样式,但是元素包含field_with_errors div:

Here I don't get the Zurb styling but the element is wrapped with field_with_errors div:

.field
  = f.label :name
  = f.input :name, :class => "input-text"

所以基本上看来f.text_field帮助者绕过了Rails视图机制

So basicly it seems the f.text_field helper somehow bypasses the Rails view mechanism of providing div classes to show the errors.

推荐答案

如果你想传递 class 到SimpleForm的输入,你应该使用

If you want to pass class to SimpleForm's input you should use

= f.input :name, :input_html => { :class => 'input-text' }

这篇关于不包括使用field_with_errors的css div为使用f.text_field创建的字段,但适用于f.input的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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