如果输入未通过验证,则输入后会显示错误标签,但保留输入名称的第一个标签会消失。有任何想法吗?感谢。
验证前
<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 %>
初始化/ 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
宝石