Andrew Stewart
2006-Oct-04 10:12 UTC
Displaying validates_acceptance_of Errors In A Check Box
Hello,
I am having trouble displaying a check box which must be checked but
hasn''t been. I would like it to be highlighted as in a scaffolded
view but the hidden check box field which is generated by the
check_box helper is also highlighted, and the text next to it loses
its styling.
My code follows. Should I get cleverer with the CSS or write my own
check_box helper which wouldn''t wrap both the visible and the hidden
check boxes in <div class=''fieldWithError'' /> tags -- or
something
else altogether?
In my customer model I have:
validates_acceptance_of :terms
In my view I have:
<% form_for :customer, @customer, :url => { :action => :store } do |
c| %>
<p><%= c.check_box :terms %> I have read and agree to the
Software
Licence Agreement.</p>
<%= submit_tag %>
<% end %>
When the user submits the form without ticking the box, the view
renders again with erroneous fields highlighted as in a scaffolded view.
The HTML generated for the check box is:
<p><div class="fieldWithErrors"><input
id="customer_terms"
name="customer[terms]" type="checkbox" value="1"
/></div><div
class="fieldWithErrors"><input name="customer[terms]"
type="hidden"
value="0" /></div> I have read and agree to the Software
Licence
Agreement.</p>
The CSS is:
.fieldWithErrors {
border: 1px solid red;
padding: 2px;
display: inline;
}
And the result unfortunately is that both the visible and invisible
check boxes are given a border and the text ("I have read....") loses
the styling for <p/> tags.
Thanks in advance,
Andy Stewart
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Ruby on Rails: Talk" group.
To post to this group, send email to
rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk
-~----------~----~----~----~------~----~------~--~---
