2

入力が検証に合格しない場合、入力の後にエラー ラベルが表示されますが、入力名を保持する最初のラベルは消えます。何か案は?ありがとう。

検証前

<div class="field">
 <label class="default-label" for="user_email">Email</label>
 <input class="default-input" id="user_email" name="user[email]" size="30" type="email" value="" />
</div>

検証後

<div class="field">
 <div class="field_with_errors">
  <input class="default-input" id="user_email" name="user[email]" size="30" type="email" value="" />
  <label for="user_email" class="message">has already been taken</label>
 </div>
</div

_form.html.erb

<%= form_for @user, :validate => true, :url => users_path, :method => :post do |f| %>

 <div class="field"><%= f.label :email,  { :class => "default-label" } %>
 <%= f.text_field :email,  { :class => "default-input" }  %></div>

 <div class="actions"><%= f.submit "Go!", :class => "default-button" %></div>

<% end %>

initializers/client_side_validations.rb

require 'client_side_validations/simple_form' if defined?(::SimpleForm)
require 'client_side_validations/formtastic'  if defined?(::Formtastic)

ActionView::Base.field_error_proc = Proc.new do |html_tag, instance|
  unless html_tag =~ /^<label/
    %{<div class="field_with_errors">#{html_tag}<label for="#{instance.send(:tag_id)}" class="message">#{instance.error_message.first}</label></div>}.html_safe
  else
    %{<div class="field_with_errors">#{html_tag}</div>}.html_safe
  end
end

宝石

  • レール3.1.0
  • client_side_validations 3.1.0
4

1 に答える 1

1

プロジェクトで同じ問題が発生し、github リポジトリでこの問題を見つけました

そこで提案されたフォークを使用しましたが、すべて正常に機能しました。

于 2012-02-22T20:06:15.427 に答える