Hello list, I''m trying to autocomplete a simple text field on a form, but I can''t get any of the autocomplete "options" to appear onscreen. Watching the log, it seems that the requests are being sent out to my database server each time I type in a character in the field, and a response is coming back, but nothing ever shows up on screen. I can also see the stylesheet and prototype.css and controls.css files being loaded OK. On that basis, I suspect the issue is in my partial or view, but I just can''t see what it is. Key bits of info: create table apps ( id ... app varchar2(20), ... ) Note that my table and field names are "apps" and "app" respectively. In the view, <%= stylesheet_link_tag ''style'' %> <%= javascript_include_tag "prototype" %> <%= javascript_include_tag "controls" %> ... <%= start_form_tag :action => ''show'', :id => @app %> OR enter the name of an application here<br/> <%= text_field_with_auto_complete ''app'', ''app'' %><br/> <%= submit_tag ''Find it'' %> <%= end_form_tag %> In the controller, class AppsController < ApplicationController auto_complete_for :app, :app ... def auto_complete_for_app_app search = params[:app][:app] @apps = App.find(:all, :conditions => [''LOWER(apps.app) LIKE ?'', ''%'' + search.downcase + ''%''], :order => ''apps.app ASC'') render :partial => ''apps'' end The entire partial (app\views\apps\_apps.rhtml), <ul class="applications"> <% for a in @apps do -%> <li class="app"> <div class="appname"><%=h a.app %></div> </li> <% end -%> </ul> Finally, style.css: body, p, ol, ul, td { font-family: arial, helvetica, sans-serif; font-size: 0.9em; line-height: 1.3em; } div.auto_complete { position: absolute; left: 2em; z-index: 100; background-color: white; } I''ve been banging my head against the wall for several hours on this, grabbing stuff out of Google and trying it, all to no avail. Could someone please point out the (I''m guessing) really obvious error in what I''m doing? Thanks in advance Dave M.
You need to include "effects.js". So, add <%= javascript_include_tag "effects" %> to your view. Alternatively, (and recommended) use <%= javascript_include_tag :defaults %> which will include all JavaScript files automatically, and in the correct order. Also, be sure to use a browser with decent Javascript console information, like Firefox, which will allow you to pinpoint problems more easily. :) Thomas Am 01.08.2005 um 10:25 schrieb David Mitchell:> Hello list, > > I''m trying to autocomplete a simple text field on a form, but I can''t > get any of the autocomplete "options" to appear onscreen. Watching > the log, it seems that the requests are being sent out to my database > server each time I type in a character in the field, and a response is > coming back, but nothing ever shows up on screen. I can also see the > stylesheet and prototype.css and controls.css files being loaded OK. > > On that basis, I suspect the issue is in my partial or view, but I > just can''t see what it is. > > Key bits of info: > > create table apps ( > id ... > app varchar2(20), > ... > ) > > Note that my table and field names are "apps" and "app" respectively. > > > In the view, > > <%= stylesheet_link_tag ''style'' %> > <%= javascript_include_tag "prototype" %> > <%= javascript_include_tag "controls" %> > ... > <%= start_form_tag :action => ''show'', :id => @app %> > OR enter the name of an application here<br/> > <%= text_field_with_auto_complete ''app'', ''app'' %><br/> > <%= submit_tag ''Find it'' %> > <%= end_form_tag %> > > > In the controller, > > class AppsController < ApplicationController > auto_complete_for :app, :app > > ... > def auto_complete_for_app_app > search = params[:app][:app] > @apps = App.find(:all, > :conditions => [''LOWER(apps.app) LIKE ?'', > ''%'' + search.downcase + ''%''], > :order => ''apps.app ASC'') > render :partial => ''apps'' > end > > > The entire partial (app\views\apps\_apps.rhtml), > > <ul class="applications"> > <% for a in @apps do -%> > <li class="app"> > <div class="appname"><%=h a.app %></div> > </li> > <% end -%> > </ul> > > > Finally, style.css: > > body, p, ol, ul, td { > font-family: arial, helvetica, sans-serif; > font-size: 0.9em; > line-height: 1.3em; > } > div.auto_complete { > position: absolute; > left: 2em; > z-index: 100; > background-color: white; > } > > I''ve been banging my head against the wall for several hours on this, > grabbing stuff out of Google and trying it, all to no avail. > > Could someone please point out the (I''m guessing) really obvious error > in what I''m doing? > > Thanks in advance > > Dave M. > _______________________________________________ > Rails mailing list > Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > http://lists.rubyonrails.org/mailman/listinfo/rails >
Aaaaargh! I vaguely remember reading that just before I got diverted into a pointless hour-long meeting, then not following up on it afterwards. Thanks Thomas - I''ll try it at work tomorrow (Tuesday, here in Australia). Dave M. On 8/1/05, Thomas Fuchs <thomas-9D208sng4xU@public.gmane.org> wrote:> You need to include "effects.js". So, add > <%= javascript_include_tag "effects" %> > to your view. > > Alternatively, (and recommended) use > <%= javascript_include_tag :defaults %> > which will include all JavaScript files automatically, and in the > correct order. > > Also, be sure to use a browser with decent Javascript console > information, like Firefox, which will allow you to pinpoint problems > more easily. :) > > Thomas > > Am 01.08.2005 um 10:25 schrieb David Mitchell: > > > Hello list, > > > > I''m trying to autocomplete a simple text field on a form, but I can''t > > get any of the autocomplete "options" to appear onscreen. Watching > > the log, it seems that the requests are being sent out to my database > > server each time I type in a character in the field, and a response is > > coming back, but nothing ever shows up on screen. I can also see the > > stylesheet and prototype.css and controls.css files being loaded OK. > > > > On that basis, I suspect the issue is in my partial or view, but I > > just can''t see what it is. > > > > Key bits of info: > > > > create table apps ( > > id ... > > app varchar2(20), > > ... > > ) > > > > Note that my table and field names are "apps" and "app" respectively. > > > > > > In the view, > > > > <%= stylesheet_link_tag ''style'' %> > > <%= javascript_include_tag "prototype" %> > > <%= javascript_include_tag "controls" %> > > ... > > <%= start_form_tag :action => ''show'', :id => @app %> > > OR enter the name of an application here<br/> > > <%= text_field_with_auto_complete ''app'', ''app'' %><br/> > > <%= submit_tag ''Find it'' %> > > <%= end_form_tag %> > > > > > > In the controller, > > > > class AppsController < ApplicationController > > auto_complete_for :app, :app > > > > ... > > def auto_complete_for_app_app > > search = params[:app][:app] > > @apps = App.find(:all, > > :conditions => [''LOWER(apps.app) LIKE ?'', > > ''%'' + search.downcase + ''%''], > > :order => ''apps.app ASC'') > > render :partial => ''apps'' > > end > > > > > > The entire partial (app\views\apps\_apps.rhtml), > > > > <ul class="applications"> > > <% for a in @apps do -%> > > <li class="app"> > > <div class="appname"><%=h a.app %></div> > > </li> > > <% end -%> > > </ul> > > > > > > Finally, style.css: > > > > body, p, ol, ul, td { > > font-family: arial, helvetica, sans-serif; > > font-size: 0.9em; > > line-height: 1.3em; > > } > > div.auto_complete { > > position: absolute; > > left: 2em; > > z-index: 100; > > background-color: white; > > } > > > > I''ve been banging my head against the wall for several hours on this, > > grabbing stuff out of Google and trying it, all to no avail. > > > > Could someone please point out the (I''m guessing) really obvious error > > in what I''m doing? > > > > Thanks in advance > > > > Dave M. > > _______________________________________________ > > Rails mailing list > > Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > > http://lists.rubyonrails.org/mailman/listinfo/rails > > > >