私はいくつかのajax検証を自分のフォームで実行しようとしていて、少し問題が発生しています。
私のフォームには次のようなコードがあります。
<% form_for @user, :html => { :id => 'user_form', :multipart => true } do |f| %>
<%= f.label :username %><br />
<%= f.text_field :username %> <%= error_message_on :user, :username %>
</p>
<p>
<%= f.label :email %><br />
<%= f.text_field :email %> <%= error_message_on :user, :email %>
</p>
#other form fields (password and confirmation)
Type the words below to prove you aren't a robot: <%= recaptcha_tags %>
<%= error_message_on :user, :base %>
<p><%= f.submit "Submit" %></p>
<% end %>
<%= observe_form "user_form", :url => users_path %>
これにより、ajaxを使用しない場合はエラーが正常に表示されますが、可能であればonblurアクションを使用して、「error_message_on」部分をajaxで表示および非表示にする方法がわかりません。
私のコントローラーは正常に動作するので、ここにコードを配置しません。
誰かがここの空白を埋めることができるかどうか疑問に思いました:
validate.js.rjs内:
#enables and disables the submit button on the bottom
if @user.valid?
page[:user_submit].enable
else
page[:user_submit].disable
end
page.select('.formError').each(&:remove)
#Some code to add the form error
#Some code to highlight the error field
私がやろうとしていることを視覚的に理解するために、ここに私のcssがあります。
.formError {
color: #D00;
font-size: 12px;
font-weight: bold;
}
.fieldWithErrors input {
border: 5px solid #f66;
}