Further googling finally revealed the answer:
from http://www.sergiopereira.com/articles/prototype.js.html at the
end of the section: Using the Ajax.Updater class:
<quote>
In case you've tried it before, you know it doesn't work. The reason
is that the script block will be evaluated, and evaluating a script
like the above will not create a function named sayHi. It will do
nothing. To create this function we need to change our script to
create the function. See below.
<script language="javascript" type="text/javascript">
sayHi = function(){
alert('Hi');
};
</script>
<input type="button" value="Click Me" onclick="sayHi()"/>
Note that in the previous example we did not use the var keyword to
declare the variable. Doing so would have created a function object
that would be local to the script block (at least in IE). Without the
var keyword the function object is scoped to the window, which is our
intent.
</quote>
So, by editing my lookup_field helper (which was copied from the
ActionView::Helpers::JavascriptMacrosHelpers#auto_complete_field
helper) to not include the "var" at the beginning of my declaration,
the whole thing now works as expected.
def lookup_field(field_id, options = {})
function = "#{field_id}_auto_completer = new
Lookup.Autocompleter("
function << "'#{field_id}', "
function << "'" + (options[:update] ||
"#{field_id}_auto_complete") + "', "
function << "'#{url_for(options[:url])}'"
... ...
function << (', ' + options_for_javascript(js_options) + ')')
javascript_tag(function)
end
whereas the first line (and the auto_complete_field helper) read:
function = "var #{field_id}_auto_completer = new
Lookup.Autocompleter("
Is there a good argument for including the "var" in the first place?
Would this be something that should be changed in the rails helpers?
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Ruby
on Rails: Spinoffs" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at
http://groups.google.com/group/rubyonrails-spinoffs?hl=en
-~----------~----~----~----~------~----~------~--~---