Topic: question about observe_field

I have set up a fairly simple requirement search on my database using observe_field with Ajax. Everything seems to be working fine, except for one problem.  When I type in a few characters, it automatically searches and refreshes the page with the correct information.  The problem is that if I type in several characters and then press enter, I get no results returned.  Is there a way to handle this such that the results of the query will be returned after pressing enter or is that not possible?

I've included the code if it helps.

index.rhtml

<%= form_tag nil, { :id => 'search_form' } %>
Search by Requirement:
<%= text_field_tag 'search' %>
<%= end_form_tag %>
<p>Search Results:</p>
<br />
<div id="results">
</div>
<%= observe_form :search_form,
     :frequency => 0.5,
     :update => 'results',
     :url => { :action => 'search_by_req' } %>

reqs_controller.rb
  def search_by_req
    @results = Req.find( :all, :conditions => [ "Requirement LIKE ?", "%#{params[:search]}%" ] )
    render :layout=>false
  end

Last edited by tschoen16 (2007-01-05 12:03:26)

Re: question about observe_field

When pressing enter it is actually submitting the form, so the observe form isn't being triggered at all. Do you want it to perform the same behavior as the observe_form does? If so, try a form_remote_tag and give it the same action/url as the observe_form.

Railscasts - Free Ruby on Rails Screencasts

Re: question about observe_field

as always, thanks Ryan.