【问题标题】:fieldWithErrors not wrapping every error fieldfieldWithErrors 不包装每个错误字段
【发布时间】:2010-06-05 03:17:54
【问题描述】:

当我提交空白的 :title 和 :description 字段时,请注意以下结果

Error div tags only wraps the title text field and not the description text area. http://www.freeimagehosting.net/uploads/c14b4a2d74.png

验证在控制器中:

class Question < ActiveRecord::Base
  validates_presence_of :title
  validates_presence_of :description

并且,表单是使用这些名称生成的:

-form_for(@question) do |f|
  = f.error_messages
  = f.label :title
  = f.text_field :title, :size => 50, :onchange => remote_function(:url => {:action => :display_tag_suggestions}, :with => 'Form.Element.serialize(this)')
  #suggestions
  = f.label :description
  = f.text_area :description
  ...

但是,由于某种原因,只有 :title 被包裹在错误 div 标签中:

<form action="/questions" class="new_question" id="new_question" method="post">
  <div style="margin:0;padding:0"><input name="authenticity_token" type="hidden" value="6HQaiu1D0gBQcKw2pLeZP6Jvn0FSClPD5Sk9HwegzPg=" /></div>
  <div class="errorExplanation" id="errorExplanation">
    <h2>2 errors prohibited this question from being saved</h2>
    <p>There were problems with the following fields:</p>
    <ul>
      <li>Title can't be blank</li>
      <li>Description can't be blank</li>
    </ul>
  </div>
  <label for="question_title">Title</label>
  <div class="fieldWithErrors"><input id="question_title" name="question[title]" onchange="new Ajax.Request('/questions/display_tag_suggestions', {asynchronous:true, evalScripts:true, parameters:Form.Element.serialize(this) + '&amp;authenticity_token=' + encodeURIComponent('6HQaiu1D0gBQcKw2pLeZP6Jvn0FSClPD5Sk9HwegzPg=')})" size="50" type="text" value="" /></div>
  <label for="question_description">Description</label>
  <textarea cols="40" id="question_description" name="question[description]" rows="20"></textarea>
  ...

我不认为这种行为是意料之中的。大多数人遇到的问题是它用 div 包装东西,无法正常显示。我的问题是字段没有被 div 包裹!

我没有对错误的处理方式做出任何(有意识的)改变,所以我不确定为什么它不能正常工作。

【问题讨论】:

  • 在所有其他样式表之后添加scaffold.css
  • 我只使用一个样式表,并且我已经尝试将scaffold.css 的内容添加到其中。但这并不能解决问题。 div 没有包装描述 html 标记。

标签: ruby-on-rails css error-handling haml


【解决方案1】:

您使用的是哪个版本的 Haml?一些旧版本在错误包装方面存在兼容性问题。

【讨论】:

  • 你已经过时了。升级到 3.0.9,希望这应该会消失。
猜你喜欢
  • 1970-01-01
  • 2010-10-19
  • 2010-12-29
  • 2013-06-19
  • 2011-07-18
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多