Email field:
<label for="job_client_email">Email: </label>
<input type="email" name="job[client_email]" id="job_client_email">
looks like this:
But, if the email validation fails, it becomes:
<div class="field_with_errors">
<label for="job_client_email">Email: </label>
</div>
<div class="field_with_errors">
<input type="email" value="wrong email" name="job[client_email]" id="job_client_email">
</div>
which looks like this:
How could I avoid this appearance change ?
You should override ActionView::Base.field_error_proc
. It's currently defined as this within ActionView::Base
:
@@field_error_proc = Proc.new{ |html_tag, instance|
"<div class=\"field_with_errors\">#{html_tag}</div>".html_safe
}
You can override it by putting this in your application's class inside config/application.rb
:
config.action_view.field_error_proc = Proc.new { |html_tag, instance|
html_tag
}
Restart rails server for this change to take effect.