# Wierd issues with autocomplete and prototype

**URL:** <https://www.ruby-forum.com/t/wierd-issues-with-autocomplete-and-prototype/89200>\
**Category:** Rails\
**Created:** [March 18, 2007, 3:31pm UTC](https://www.ruby-forum.com/t/wierd-issues-with-autocomplete-and-prototype/89200 "2007-03-18T15:31:29Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![flip](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/f/53a042/32.png) [@flip](https://www.ruby-forum.com/u/flip)\
**Post date:** [March 18, 2007, 3:31pm UTC](https://www.ruby-forum.com/t/wierd-issues-with-autocomplete-and-prototype/89200/1 "2007-03-18T15:31:29Z")

</div>

I have been trying to figure out an issue that I have run in to for  
the last couple of days. I am using autocomplete in a few areas in my  
project to pull up a list of things when adding something that has a  
relationship so that a user doesn’t create duplicates. In some cases  
the fields for those objects are being added to the form after a user  
clicks on a add thing link and in other cases the fields are being  
built when the page loads. The issue I am having is that if I use the  
exact same code for the fields it works when I add the fields after  
the form has been generated via ajax but doesn’t work when the fields  
are present on page load. I am running on edge rails and here is an  
example of the code being used:

\<%= text\_field\_tag(“publisher\_name”, nil, {:size =\> 30, :class =\>  
“inputText”}) %\>  
\<%= auto\_complete\_field(“publisher\_name”, :url =\>  
auto\_complete\_publishers\_path, :method =\> :get) %\>

Basically I am using a custom auto complete function and my app is  
REST based. I have routes set up and as I mentioned everything works  
as advertised in one case but not the other.

When I add the field on page load of the form I get the following  
error from prototype:

hide(null)prototype.js (line 1153)  
baseInitialize(“publisher\_name”, “publisher\_name\_auto\_complete”,  
Object paramName=publisher\_name tokens=[0] frequency=0.4)controls.js  
(line 84)  
initialize(“publisher\_name”, “publisher\_name\_auto\_complete”, “/  
publishers;auto\_complete”, Object paramName=publisher\_name tokens=[0]  
frequency=0.4)controls.js (line 335)  
create()prototype.js (line 23)  
[Break on this error] $(element).style.display = ‘none’;

Any one have any idea what is going on?

---

<div class="post-metadata">

**Author:** ![flip](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/f/53a042/32.png) [@flip](https://www.ruby-forum.com/u/flip)\
**Post date:** [March 18, 2007, 4:11pm UTC](https://www.ruby-forum.com/t/wierd-issues-with-autocomplete-and-prototype/89200/2 "2007-03-18T16:11:34Z")

</div>

Well I feel dumb. On a whim I decided to move the auto\_complete\_field  
tag to below the div it is set to update and everything works  
correctly. Guess I didn’t try everything I could think of till this  
morning.
