2006-04-14 (金) [長年日記]
1
.fieldWithErrosがtextareaだけ変な件
ぐぐっても見つからなかったんだけど、みんなおかしいと思わなくって?
まず、DIVじゃなくてSPANで囲むようにする。
module ActionView
class Base
@@field_error_proc = Proc.new{ |html_tag, instance|
"<span class=\"fieldWithErrors\">#{html_tag}</span>"
}
cattr_accessor :field_error_proc
end
end
で、CSSをtextareaとその他に分ける。
.fieldWithErrors input {
border: 1px solid #f00;
}
.fieldWithErrors select {
border: 1px solid #f00;
}
.fieldWithErrors textarea {
border: 1px solid #f00;
}
firefoxだとradiobuttonはあんまり変更できないんだなあ。
あきらめろ。
2
ファイルアップロードのvalidates
ファイルアップロードとかってフォームと属性の名前が違うのでvalidates_presence_ofとか使ってもエラーでフォームが赤くならねーみたいなことになったりするので自前で用意。
def validates
unless @image.blank?
if invalid
errors.add(:file, '不正ですぞよ')
end
else
errors.add(:file, 'を入力して下さい')
end
end
3
option_groups_from_collection_for_select 使ったらfieldWithErrorsが出なくなるよ
自分でヤル。
<% if error_message_on "foo", 'bar' %> <span class="fieldWithErrors"> <% end %> <select ...> <%= option_groups_from_collection_for_select( ... ) %> </select> <% if error_message_on "foo", 'bar' %> </span> <% end %>
[]
| 
module ActionView<br>はどこのファイルに書きますか?
pluginとかlibとかですかね。