Christophe --

With a few exceptions, you've got the jist of it -- step 5 is exactly
right
and the root of my problem -- I can't see the original Autocompleter
variable,
either in Firebug, or call it through an RJS or an "onSuccess" call of
the remote
form.

Actually my Autocompleter isn't Local -- it's extended from
Ajax.Autocompleter :

var Lookup = {};
Lookup.Autocompleter = Class.create();
Object.extend(Object.extend(Lookup.Autocompleter.prototype,
Ajax.Autocompleter.prototype), {
  initialize: function(element, update, url, options) {
    this.baseInitialize(element, update, options);
    this.options.asynchronous  = true;
    this.options.onComplete    = this.onComplete.bind(this);
    this.options.defaultParams = this.options.parameters || null;
    this.url                   = url;
    this.idFieldId             = this.getIdFieldId(this.options);
    this.idField               = $(this.idFieldId);
            .... .....
    this.newObjectUrl          = this.options.newObjectUrl;
    this.targetObject                                    = 
this.options.targetObject || null;
    this.setCreateNewDiv(options);
    this.options.afterUpdateElement = this.afterUpdateElement;
  },
 etc.

Actually the first step on the page I'd trying to debug now is to
load
a "show" page of the parent object that doesn't orginally include the
autocompleter,
in this case "play.rhtml". That just lists the attributes of a play.
To add an
author (or composer, or lyricist) to the play, you click to
link_to_remote
anchor which updates a div with the form for a "contribution", which
is a join object
linking an artistic_work, an artist, and an artistic_role.

That Ajax-loaded form rhtml includes a hidden input field for the
artist_id and a "lookup" field for the artist -- too many for a
drop down, and I don't want them to be able to input someone I don't
have an id for
since I'm creating a join object that has "artist" as a belongs_to.

The Lookup is obviously reaching my page, as all the ajaxy goodness
happens
and my extensions are being called, etc. By overriding onComplete, I
have the
page give the option to create a new target object by calling up a
remote_form
for the target object:

onComplete: function(request) {
   this.update.innerHTML = request.responseText;
   if(this.update.firstChild &&
this.update.firstChild.childNodes.length == 1 ){
      if(!this.changed && this.hasFocus) {
        li = document.createElement('li');
        li.innerHTML = "Not found. Click here to create."
        Element.addClassName(li,"selected")
        Event.observe(li,"click",
this.createNewObject.bindAsEventListener(this));
        this.update.firstChild.appendChild(li);
        if(this.hasFocus) {
          this.show();
          this.active = true;
        }
      }
      this.entryCount = 0;
      this.stopIndicator();
      this.index = 0;
    } else {
      this.updateChoices(request.responseText);
    }
  },

The form which is called up by this.createNewObject takes all the
attributes
of the target object (artist) creates and saves a new active record
(via Ajax calls)
, and returns the id and name so that they can be populated into the
original form.

That's where I get stuck.

Do variables that are set to the window via "evalScripts" (which is
how the "lookup" autocompleter
got there in the first place) reside in the same window context as
variables included
statically on the orginal page, or is there a special way to access
them?

Still stuck, so any thoughts appreciated.

John




On Feb 23, 3:16 am, Christophe Porteneuve <[EMAIL PROTECTED]> wrote:
> Hey John,
>
> Before diving further into a client-side maintainance, is there any
> reason why your AC class is Local, instead of being AJAXy (if you used
> Ajax.Autocompleter as a base, you would, by definition, always get the
> latest information from the server side)?
>
> If we stay client-side (which I'm not too fond of for AC's), I need to
> make sure I understand what you're saying:
>
> 1) The page loads
> 2) At some point in this loading process there's an inline script that
>     defines your AC variable.
> 3) The user looks up something (among local client-side data), doesn't
>     find it, gets a <li> that lets them create it
> 4) They click, get a form, fill it up, submit it (which is intercepted
>     and then done through AJAX)
> 5) The server-side returns an RJS-created JS call that attempts to
>     invoke a method on your local AC, as created on step 2.  The
>     reference cannot be found.
>
> Is this the actual scheme for your problem?
>
> --
> Christophe Porteneuve aka TDD
> [EMAIL PROTECTED]


--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---

Reply via email to