I finally figured out my issue.

I was being bitten by the fact that evalScripts evals scripts in the local
scope to the prototype object.

This was fine when my script was loaded from the start, but if that script
was drawn to the page via an AJAX call it would get executed in the wrong
scope and all weird things would start happening.

On Tue, Mar 15, 2011 at 5:59 PM, joe t. <thooke...@gmail.com> wrote:

> When the Autocompleter is initialized, the options are set as such:
>
> ...
> this.options.minChars = this.options.minChars || 1;
> ...
>
> Your 0 evaluates as false-ish, so trips over to 1. i'm pretty sure the
> reason for requiring at least 1 character in the lookup string is that
> the result list attempts to highlight the matching string pattern in
> bold, so when that string is empty, it could cause problems. Mostly
> that's a guess, but that line in the Autocompleter.baseInitialize is
> why you can't get a list on empty - it's not actually using your 0.
>
> As for why it generates a request on the empty string...i believe
> that's being triggered by the onKeyPress handler. It's intended to
> handle key navigation for the INPUT vs. the results list. Since it
> doesn't trap DELETE or BACKSPACE, it simply less their events pass
> through the handling down to this section:
> ////
> this.changed = true;
> this.hasFocus = true;
>
> if(this.observer) clearTimeout(this.observer);
> this.observer = setTimeout(this.onObserverEvent.bind(this),
> this.options.frequency*1000);
> ////
>
> It tells other methods that the value has changed, has focus, and
> resets a timer to call the next Ajax request. Since you're handling
> empty strings on your server side, you see a successful round-trip
> AJAX request. But Autocompleter doesn't do anything with the result
> per the reason above.
>
> You'd have to write an override function of some sort, and make sure
> that the empty string doesn't harm other areas of the Autocompleter
> class.
>
> However, i recommend that you note to your user they can use some
> special character (usually *) to "search all", then handle the "*" on
> the server side.
> -joe t.
>
>
>
>
> On Mar 15, 12:58 pm, pipplo <joe.kos...@gmail.com> wrote:
> > Ok, I've done some more debug.
> >
> > The autocomplete text box works still.  But it doesn't seem to work
> > with 0 chars.
> >
> > I can see when the user clicks in the text box a request is generated,
> > and a response is generated. I can use the chrome debugger to see that
> > the response is as expected.
> >
> > The AJAX request seems to just not render the HTML when the number of
> > chars is 0, even though it does all the work to generate a request and
> > parse the response. As soon as I type a character I get the expected
> > auto-complete results displayed.  When I backspace back to 0 chars it
> > doesn't display anything, but it still does the AJAX request.
> >
> > There must be a place in prototype.js where there is a decision to
> > render the html or not?  I can't seem to find it.  So I'm just looking
> > for some hints on why that wouldn't happen sometimes..
> >
> > On Mar 14, 11:27 am, pipplo <joe.kos...@gmail.com> wrote:
> >
> >
> >
> >
> >
> >
> >
> > > I have a weird bug that I'm having trouble debugging. I am using Rails
> > > but I think the issue is in the javascript handling somewhere.
> >
> > > I have a div with a form and autocomplete
> >
> > > <div id=form>
> > >  <form info>
> > >     <autocomplete box>
> > >  </form>
> > > </div>
> >
> > > I have the options set so that when the user clicks in the auto-
> > > complete they get an initial list (minChars = 0)
> >
> > > When the user types a user name in the autocomplete and selects one of
> > > the drop down options I generate a request via Ajax and render the
> > > form again without the autocomplete. The user can then click 'remove'
> > > to remove the user info and re-draw the autocomplete box.
> >
> > > After the re-draw the minChars = 0 doesn't work.  Whenever I click in
> > > the box I see a request generated to my controller, and I return the
> > > correct information but it doesn't get rendered into HTML and I dont
> > > see a drop down.
> >
> > > If the user types a letter or name then the dropdown lits does show
> > > up, but the initial ajax request never gets reflected.
> >
> > > I assume there is some state variable that thinks the text box hasn't
> > > changed value or something which is preventing actually rendering the
> > > HTML returned by Rails.
> >
> > > I hope that makes sense.  Any ideas?
> >
> > > P.S. My current workaround is to just hide the autocomplete field and
> > > not render it empty.  This works but won't be usable in other parts of
> > > my site.
>
> --
> You received this message because you are subscribed to the Google Groups
> "Prototype & script.aculo.us" group.
> To post to this group, send email to
> prototype-scriptaculous@googlegroups.com.
> To unsubscribe from this group, send email to
> prototype-scriptaculous+unsubscr...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/prototype-scriptaculous?hl=en.
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"Prototype & script.aculo.us" group.
To post to this group, send email to prototype-scriptaculous@googlegroups.com.
To unsubscribe from this group, send email to 
prototype-scriptaculous+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/prototype-scriptaculous?hl=en.

Reply via email to