Topic: How to get observe_field to work?

Hello all,

I am trying to use observe_form to perform a customised live search, but i cant get it working.

here's the code for my view:

<input id="live-search" name="search" type="text" value=""%>
<%= observe_field ('search', :frequency=>0.5,
    :update=>"search-results",
    :url=> [:controller =>"place", :action=>"live_search"])%>
<div id='search-results'></div>

here's the code for the place controller:
  def live_search
    #@places = Places.find(:all,
      #:conditions=>['LOWER(name) LIKE ? or LOWER(aka) LIKE ? or name_chn LIKE ?', '%' + request.raw_post.downcase + '%'])
      #render :partial => "live_search_result"
      render :text=>"blah blah blah"
  end

when i tried to put some text in the text field, nothing happened, i checked the development log, there's no data coming from the browser.

here's the code it generates:

<input id="live-search" name="search" type="text" value=""%>
<script type="text/javascript">
//<![CDATA[
new Form.Element.Observer('search', 0.5, function(element, value) {new Ajax.Updater('search-results', '', {asynchronous:true, evalScripts:true, parameters:value})})
//]]>

</script>
<div id='search-results'></div>


how do i get it to work? thank you.

Re: How to get observe_field to work?

You could try something like the following in the views:

<div id="live_search">
  <form><%= text_field_tag :search %>
    <% if params[:search] != nil %>
      <%= link_to 'All', {:action => :index, :searchtext => nil} %>
    <% end %>
  </form>
</div>

<%= observe_field :search, :url => { :action => :live_search}, :frequency => 10, :update => "search_results", :with => :search %>


And the controller might have something like this:

def live_search
  redirect_to :action => "index", :search => params[:search]
end

I'm not sure what action you want to redirect to, tho...I'm just assuming you want the index page to rerender with the search results. If this is the case, you may have to add some code to the index part of the controller.