Hello all, I''m in need of some Ajax masters... I have a live search form for entering data using the observe_field helper. It works great so far. I type a bit, find the option I''m looking for, and it adds to my list. The problem comes when I type really fast and hit the add button. It adds to my list just fine, but the observer starts its ajax search anyway and shows me results. Thanks, but no thanks. I''m not quite sure how Prototype handles this stuff. Is there a single Ajax request object doing all the work, or does each form, link, observer, etc have a seperate request? Would there be a way to get a reference to it and cancel it? Or better yet, disable the observer until I need it again. Now that I type this, I''m thinking I may be able to get a reference to the Request through the loading event possibly. I''ll look into it later. -- rick http://techno-weenie.net
Hi, 1) In prototype, each Ajax request gets it''s own request object 2) the loading event should allow for a :loading => ''request.abort()'' or so... If do the "new Ajax.Request(...)" javascript manually, you can get a js object var like this: "var x = new Ajax.Request(...)". You should then a able to call "x.transport.abort()". Of course, this is completely untested... :) -- thomas Am 09.05.2005 um 16:16 schrieb Rick Olson:> Hello all, I''m in need of some Ajax masters... > > I have a live search form for entering data using the observe_field > helper. It works great so far. I type a bit, find the option I''m > looking for, and it adds to my list. > > The problem comes when I type really fast and hit the add button. It > adds to my list just fine, but the observer starts its ajax search > anyway and shows me results. Thanks, but no thanks. > > I''m not quite sure how Prototype handles this stuff. Is there a > single Ajax request object doing all the work, or does each form, > link, observer, etc have a seperate request? Would there be a way to > get a reference to it and cancel it? Or better yet, disable the > observer until I need it again. > > Now that I type this, I''m thinking I may be able to get a reference to > the Request through the loading event possibly. I''ll look into it > later. > -- > rick > http://techno-weenie.net > _______________________________________________ > Rails mailing list > Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > http://lists.rubyonrails.org/mailman/listinfo/rails >
How about clearing the observed text field after user had pressed the "add" button? And to avoid doing searches after field reset add a condition to skip if field is empty. Something roughly looking like: <input type="text" id="q" name="q" value=""/> <%= observe_field "q", :frequency => 1, :url => { :controller => "live", :action => "search" }, :condition => "$(\"q\").value != \"\"", :update => "search_results" -%> Unfortunately now I''m not near server to try this out. Could you please see if this is enough? On 5/9/05, Rick Olson <technoweenie-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> Hello all, I''m in need of some Ajax masters... > > I have a live search form for entering data using the observe_field > helper. It works great so far. I type a bit, find the option I''m > looking for, and it adds to my list. > > The problem comes when I type really fast and hit the add button. It > adds to my list just fine, but the observer starts its ajax search > anyway and shows me results. Thanks, but no thanks. > > I''m not quite sure how Prototype handles this stuff. Is there a > single Ajax request object doing all the work, or does each form, > link, observer, etc have a seperate request? Would there be a way to > get a reference to it and cancel it? Or better yet, disable the > observer until I need it again. > > Now that I type this, I''m thinking I may be able to get a reference to > the Request through the loading event possibly. I''ll look into it > later. > -- > rick > http://techno-weenie.net > _______________________________________________ > Rails mailing list > Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > http://lists.rubyonrails.org/mailman/listinfo/rails >-- http://deezsombor.blogspot.com
On Tuesday, May 10, 2005, 1:03:07 AM, Dee wrote:> :condition => "$(\"q\").value != \"\"",Ruby tip: :condition => %{$("q").value != ""}, I hate backslashes :) Gavin
I dislike them to, however luckily my editor is smart enough to tell the difference between escaped and unescaped characters. Cheers, Zsombor On 5/9/05, Gavin Sinclair <gsinclair-81uBx+iSpXA0n/F98K4Iww@public.gmane.org> wrote:> On Tuesday, May 10, 2005, 1:03:07 AM, Dee wrote: > > > :condition => "$(\"q\").value != \"\"", > > Ruby tip: > > :condition => %{$("q").value != ""}, > > I hate backslashes :) > > Gavin > >-- http://deezsombor.blogspot.com
Hey, thanks for the replies everyone :) I''ll try it out tonight probably and get back to you (or I''ll probably post a blog entry on it). On 5/9/05, Thomas Fuchs <thomas-9D208sng4xU@public.gmane.org> wrote:> Or, use :condition => "$(''q'').value != ''''" > > Thats two '' and one " at the end... :) > > thomas > > Am 09.05.2005 um 17:27 schrieb Dee Zsombor: > > > I dislike them to, however luckily my editor is smart enough to tell > > the difference between escaped and unescaped characters. > > > > Cheers, > > Zsombor > > > > On 5/9/05, Gavin Sinclair <gsinclair-81uBx+iSpXA0n/F98K4Iww@public.gmane.org> wrote: > > > >> On Tuesday, May 10, 2005, 1:03:07 AM, Dee wrote: > >> > >> > >>> :condition => "$(\"q\").value != \"\"", > >>> > >> > >> Ruby tip: > >> > >> :condition => %{$("q").value != ""}, > >> > >> I hate backslashes :) > >> > >> Gavin > >> > >> > >> > > > > > > -- > > http://deezsombor.blogspot.com > > _______________________________________________ > > Rails mailing list > > Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > > http://lists.rubyonrails.org/mailman/listinfo/rails > > > > _______________________________________________ > Rails mailing list > Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > http://lists.rubyonrails.org/mailman/listinfo/rails >-- rick http://techno-weenie.net
On Tuesday, May 10, 2005, 3:44:33 AM, Rick wrote:> Hey, thanks for the replies everyone :)> I''ll try it out tonight probably and get back to you (or I''ll probably > post a blog entry on it).Perhaps you could add a Wiki entry as well: HowtoCancelAnAjaxRequest. Cheers, Gavin