title: jQuery autocompletion in a Rails form
body: <p>I have a Rails form for email, and I would like to have auto-completion in Receiver field. Here is what I did:</p>
  
  <pre><code>= f.label :recipient_id, "Send to:"
  = text_field_tag :recipient_id, nil
  :javascript
   $(function() {
      $( "#recipient_id" ).autocomplete({
          source: "#{escape_javascript url_for(:action =&gt; 'recipient_autocomplete',
                       :controller =&gt; 'sent')}",
          minLength: 2,
          select: function( event, ui ) {
              $('input#recipient_id').attr('value', ui.item.value);
              ui.item.value = ui.item.label
          }
      });
  });
  </code></pre>
  
  <p>In my controller, I have:</p>
  
  <pre><code>  def recipient_autocomplete
      @users= User.all(:conditions =&gt; ['first_name LIKE ? OR last_name LIKE?', 
        "%#{params[:term]}%", "%#{params[:term]}%"])
      render :json =&gt; @users.collect {|x| {:label=&gt;x.full_name, :value=&gt;x.id}}.compact
    end
  </code></pre>
  
  <p>The json call works fine and display full name OK. Here is the element:</p>
  
  <pre><code>&lt;input type="text" name="recipient_id" id="recipient_id" class="ui-autocomplete-input"
    autocomplete="off" role="textbox" aria-autocomplete="list" 
    aria-haspopup="true" value="158"&gt;
  </code></pre>
  
  <p>However, when I click Send (equivalent to submit), the receipient full name is sent instead of receipient_id.</p>
  
  <p>How do I tell Rails form to pick up the value (158 in the above example) of the input field instead of its label?</p>