Render autocomplete with rjs

Hello,

In my view I use an autocomplete textfield, exactly as described on
http://www.slash7.com/articles/2005/8/13/ajaxariffic-autocomplete-with-scriptaculous.
I implemented a method, say auto_complete_for_model_field which renders
the partial ‘models’:

def auto_complete_for_model_field

render :partial => ‘models’
end

This works as expected, however instead of rendering a .rhtml I want to
use a rjs template, but how do I position the list shown by the
auto_complete… method?

Hi, you can do one of the following:

a) respond_to block

 e.g.  def product
              respond_to do | format |
                format.html
                format.js { render :action => "project.rjs" }
                format.xml
              end
          end

          Note:  This will return the appropriate response based on 

the
HTTP Accept header.

b) render :action => “product.rjs”

Good luck,

-Conrad

Hi, you can also find further information in section 12.1 of the ‘Agile
Web
Development with Rails 2ed’.

-Conrad

Conrad T. wrote:

Hi, you can also find further information in section 12.1 of the ‘Agile
Web
Development with Rails 2ed’.

-Conrad

Hi Conrad,

Although respond_to is very interesting, this is not what I’m looking
for.
What I want is, when typing a character into an autocomplete textbox, I
also want to show a Save button, which is initially hidden.
Now I use this approach:

view

<%= text_field_with_auto_complete :model, :field %>
<%= observe_field(“model_field”,
:frequency => 0.1,
:url => { :action => :show_save } ) %>

Show this later
# controller auto_complete_for :contact, :name

def show_save
render :update do |page|
page.show ‘save_div’
end
end

The Observe tag looks for changes in the autocomplete textbox and
triggers a method named show_save. The show_save method displays the
element named ‘save_div’ which containts the text ‘Show this later’.
This is working, however I wonder if this can be accomplished using 1
method named auto_complete_for_model_field which displays the
autocomplete list AND show the ‘save_div’ element.

One step futher (and a little off topic): After displaying de ‘save_div’
element I want the Observer to stop observing. I tried to nest the
observe_field into a div-element (say: ‘observe_div’) and let this be
removed when the show_save method is called:

def show_save
render :update do |page|
page.show ‘save_div’
page.remove ‘observe_div’
end
end

The element is deleted, but the textbox is still being observed.