When an input doesn't pass validation, an error label appears after the input but the first label that holds inputs name disappears. Any ideas? Thanks.
before validation
<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>
after validation
<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
Gems
I had the same issue in my project and I found this issue on the github repository
I used the fork proposed there and everything worked fine.