Wes Gamble
2006-Jul-12 21:43 UTC
[Rails] Give form elements "fieldWithErrors" class in non-std. way?
All, I want to know how to force an element of my model to be invalid, but not generate any message for it, so that the corresponding form field on a form will show up with the ''fieldWithErrors'' class. I have some checkboxes on my RHTML form, and they are generated with this code <%= check_box_tag("current_job[target_list_ids][]"...etc. %> target_list_ids is an attr_accessor attribute and does not exist in the backing table for my model. If none of these checkboxes are checked when the form is submitted, the validate method puts up a message complaining. That''s fine. But I also want the fieldWithErrors style to show up on these three checkboxes to call the user''s attention to the issue. But the default mechanism for giving the error style to an element is not called for these elements (I''m doing it for text boxes just fine). Do I have to create a snippet of code in my RHTML to figure out if the target_list_ids attribute is empty (which it will be in an error condition) and then set a variable to ''fieldWithErrors'' that I can use in my check_box_tag call? e.g. <% if (error_condition) error_class = ''fieldWithErrors'' end %> <%= check_box_tag("current_job[target_list_ids][]" :class => error_class, ...%> Does that make sense? -- Posted via http://www.ruby-forum.com/.