title: Rails: Ajax form validations with error_message_on
body: <p>I've been trying to get get some ajax validations going in my form and have been running into a bit of trouble</p>
  
  <p>I have code like this in my form:</p>
  
  <pre><code>&lt;% form_for @user, :html =&gt; { :id =&gt; 'user_form', :multipart =&gt; true } do |f| %&gt;
      &lt;%= f.label :username %&gt;&lt;br /&gt;
      &lt;%= f.text_field :username %&gt; &lt;%= error_message_on :user, :username %&gt;
    &lt;/p&gt;
    &lt;p&gt;
      &lt;%= f.label :email %&gt;&lt;br /&gt;
      &lt;%= f.text_field :email %&gt; &lt;%= error_message_on :user, :email %&gt;
    &lt;/p&gt;
    #other form fields (password and confirmation)
    Type the words below to prove you aren't a robot: &lt;%= recaptcha_tags %&gt;
    &lt;%= error_message_on :user, :base %&gt;
    &lt;p&gt;&lt;%= f.submit "Submit" %&gt;&lt;/p&gt;
  &lt;% end %&gt;
  &lt;%= observe_form "user_form", :url =&gt; users_path %&gt;
  </code></pre>
  
  <p>This displays the errors fine if I don't use ajax, but I'm not sure how to make the "error_message_on" part to appear and disappear through ajax, through an onblur action if possible.</p>
  
  <p>My controller works fine so I won't place the code here.</p>
  
  <p>I was wondering if anyone could fill in the blanks here:</p>
  
  <p>in validate.js.rjs:</p>
  
  <pre><code>#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(&amp;:remove)
  #Some code to add the form error
  #Some code to highlight the error field
  </code></pre>
  
  <p>Just to give you a visual idea of what I'm trying to do, here is my css:</p>
  
  <pre><code>.formError {
    color: #D00;
    font-size: 12px;
    font-weight: bold;
  }
  
  .fieldWithErrors input {
    border: 5px solid #f66;
  }
  </code></pre>