I would like to apply a style to successfully validated fields as well as failed fields.
I am using the fields_with_errors div which is applied around form elements which fail validation. I would like to extend this behaviour to apply fields_without_errors styled div around successfully validated fields.
For example when rails validation fields, the rendered view returns as follows:
<div class="field_with_errors"><input class="input" size="30" type="text" value="" name="seller_profile[business_phone_number]" id="seller_profile_business_phone_number"></div>
The original erb code was:
<div class="row">
<label for="telephone">Company telephone</label>
<br />
<%=f.text_field :business_phone_number, :class=>"input", size:"30" %>
<div class="errors">
<%if @profile.errors[:business_phone_number].any? %>
Phone number <%= @profile.errors[:business_phone_number].join(", ")%>
<% end %>
</div>
<br />
</div>
This works very well. However for fields which have passed validation, they do not get wrapped in a div stating validation has passed.
I would like fields which pass validation to look as follows:
<div class="field_without_errors"><input class="input" size="30" type="text" value="" name="seller_profile[business_description]" id="seller_profile_business_description"></div>
I.e they are wrapped in a div with a class of "field_without_errors".Is there a way for me to add this behaviour in rails?