title: I have javascript I use to set a hidden value in a form, how do I show an error message for the associated hidden attribute?
body: <p>I have a view which has a div at the top that shows a list of images, then a form at the bottom:</p>
  
  <pre><code>%div{ id: 'how-soon' }
    %ul
      - %w( now week month browsing ).each do |hs|
        %li{ class: 'inactive', id: hs }=image_tag "how-soon/#{hs}.jpg"
  
  = simple_form_for @employer_signup, :url =&gt; url_for(:action =&gt; 'create', :controller =&gt; 'home'), method: :post do |f|
    = f.error_notification
  
    .form-inputs
      = f.hidden_field :how_soon
  
    .form-actions
      = f.button :submit, 'Join Now'
  </code></pre>
  
  <p>When a user clicks one of the images in the <code>#how-soon</code> div this coffeescript sets a hidden value in the form:</p>
  
  <pre><code>$("#how-soon &gt; ul &gt; li").click -&gt;
    $(this).siblings('.active').toggleClass('inactive active')
    $(this).toggleClass('inactive active')
    $('#employer_signup_how_soon').val($(this).attr('id'))
  </code></pre>
  
  <p>The attribute that is adjusted in the form, <code>:how_soon</code> is validated by its parent model for presence, <code>validates :how_soon, presence: true</code></p>
  
  <p>If the form is submitted without a value for <code>:how_soon</code> the form is re-displayed and I do not see the specific <code>value missing</code> error because the field is hidden.</p>
  
  <p>A typical solution to this seems to be to put the errors into the errors of another attribute and display them there, but I have no other attributes from this model being displayed that are visible, so I cannot display the errors that way.  I would do this with something like:</p>
  
  <pre><code>after_validation :validate_how_soon
  
  protected
  
  def validate_how_soon
    if errors[:how_soon].present?
      errors[:how_soon].each { |message| errors.add :first_name, message }
    end
  end
  </code></pre>
  
  <p><strong>Bonus content (may not be needed to solve my problem):</strong></p>
  
  <p>While I simplified the code above, I'm actually rendering a form using a form object that is ultimately used to create two objects, a <code>User</code> and a <code>Listing</code> (think job listing).  The attributes related to <code>Listing</code> are all hidden values filled in by the user clicking the pictures they want and having the corresponding values set via jquery in the form.  The <code>User</code> attributes are all present.  Here's the weird bit that <em>may</em> be pertinent to my issue:</p>
  
  <p>When I only have errors for visible attributes (which happen to all be <code>User</code> attributes) the errors are displayed on their attributes appropriately.  However, if I have errors on the visible attributes <em>and</em> errors on the hidden attributes none of the errors for the visible attributes are shown at all, I just get the generic <code>Please review the problems below:</code> notice at the top of the form.</p>
  
  <p>Like I said, this "bonus content" may not actually help with the problem, but I thought I'd leave it here anyway.</p>