asteriskmail-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org
2006-Dec-28 14:19 UTC
Autocompleter inside a page load in Ajax
Hi, if I update my page and try to use autocompleter does not work. The same page loaded directly work. I believe that there is a problem to get the right id. Any idea or examples how to solve this. Thank you --~--~---------~--~----~------------~-------~--~----~ 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 rubyonrails-spinoffs-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-spinoffs-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-spinoffs?hl=en -~----------~----~----~----~------~----~------~--~---
asteriskmail-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org
2006-Dec-28 15:32 UTC
Re: Autocompleter inside a page load in Ajax
UpDate in Firefox in Macbook does not work, firefox on windows is working and in IE7 does not work Any idea On Dec 28, 9:19 am, asteriskm...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org wrote:> Hi, > if I update my page and try to use autocompleter does not work. > The same page loaded directly work. > I believe that there is a problem to get the right id. > Any idea or examples how to solve this. > > Thank you--~--~---------~--~----~------------~-------~--~----~ 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 rubyonrails-spinoffs-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-spinoffs-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-spinoffs?hl=en -~----------~----~----~----~------~----~------~--~---
asteriskmail-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org a écrit :> > Hi, > if I update my page and try to use autocompleter does not work. > The same page loaded directly work. > I believe that there is a problem to get the right id. > Any idea or examples how to solve this.I suppose you mean you have some AJAX-based behavior that replaces a part of your page where you use Auto-completion? Basically, any dynamic replacement of DOM fragments that are used by such features as Draggable/Sortable/Autocompleter/etc. means extra care is necessary. Essentially, you would need to use the following sequence: 1. deregister any such behavior (Droppables.remove, Sortable.destroy, etc.) 2. actually replace the DOM fragment 3. Re-create/register the behavior (Droppables.add, Sortable.create, new Ajax.Autocompleter, etc.). This is because the features resolve IDs to actual DOM references, and then keep using those references. To nodes that get removed from the DOM by later replacement... So you need to use freshly-obtained references, even if those use the same IDs. ''HTH -- Christophe Porteneuve a.k.a. TDD "[They] did not know it was impossible, so they did it." --Mark Twain Email: tdd-x+CfDp/qHev2eFz/2MeuCQ@public.gmane.org --~--~---------~--~----~------------~-------~--~----~ 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 rubyonrails-spinoffs-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-spinoffs-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-spinoffs?hl=en -~----------~----~----~----~------~----~------~--~---
If do you have time can you explain to me a little bit more, since I do not know nothing regarding Draggable and Sortable, I will appreciate your help. Thx On 12/28/06, Christophe Porteneuve <tdd-x+CfDp/qHev2eFz/2MeuCQ@public.gmane.org> wrote:> > > asteriskmail-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org a écrit : > > > > Hi, > > if I update my page and try to use autocompleter does not work. > > The same page loaded directly work. > > I believe that there is a problem to get the right id. > > Any idea or examples how to solve this. > > I suppose you mean you have some AJAX-based behavior that replaces a > part of your page where you use Auto-completion? > > Basically, any dynamic replacement of DOM fragments that are used by > such features as Draggable/Sortable/Autocompleter/etc. means extra care > is necessary. Essentially, you would need to use the following sequence: > > 1. deregister any such behavior (Droppables.remove, Sortable.destroy, > etc.) > 2. actually replace the DOM fragment > 3. Re-create/register the behavior (Droppables.add, Sortable.create, new > Ajax.Autocompleter, etc.). > > This is because the features resolve IDs to actual DOM references, and > then keep using those references. To nodes that get removed from the > DOM by later replacement... So you need to use freshly-obtained > references, even if those use the same IDs. > > ''HTH > > -- > Christophe Porteneuve a.k.a. TDD > "[They] did not know it was impossible, so they did it." --Mark Twain > Email: tdd-x+CfDp/qHev2eFz/2MeuCQ@public.gmane.org > > > >--~--~---------~--~----~------------~-------~--~----~ 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 rubyonrails-spinoffs-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-spinoffs-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-spinoffs?hl=en -~----------~----~----~----~------~----~------~--~---
Il Neofita a écrit :> If do you have time can you explain to me a little bit more, since I do > not know nothing regarding Draggable and Sortable, I will appreciate > your help.Actually, in your specific case (which, I gather, only involved auto-completion), there are only two event handlers being created when you do: new Ajax.Autocompleter(...); - one on blur - one on keypress They both tackle your input field. When you replace the DOM fragment that contains your input field (do you really need to?!), those events never get fired again, because what the user types in is another field, a new one, created by your fragment-replacing code (e.g. the processing of a Ajax.Updater, or a call of yours to Element.replace or Element.update). It''s not too bad that you didn''t remove those two event observers; they''re not going to be triggered, and the garbage collector will handle them properly. However, what you need, at the minimum, is to follow DOM replacement by an identical call to "new Ajax.Autocompleter(...)", to recreate the functionality for your new DOM elements. Still, the question remains: why on Earth do you replace your auto-completed field (and its completion zone)? Can''t you do otherwise? -- Christophe Porteneuve a.k.a. TDD "[They] did not know it was impossible, so they did it." --Mark Twain Email: tdd-x+CfDp/qHev2eFz/2MeuCQ@public.gmane.org --~--~---------~--~----~------------~-------~--~----~ 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 rubyonrails-spinoffs-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-spinoffs-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-spinoffs?hl=en -~----------~----~----~----~------~----~------~--~---
I will try to explain what I am doing. I have a page loaded with a table, when I press in a row the table is reloaded and in the row that I selected I put the input box. If I do this the autocompleter does not work. Now, I cannot understand how I can solve this problem having the new event hadler to point to this new element. Thank you On 12/28/06, Christophe Porteneuve <tdd-x+CfDp/qHev2eFz/2MeuCQ@public.gmane.org> wrote:> > > Il Neofita a écrit : > > If do you have time can you explain to me a little bit more, since I do > > not know nothing regarding Draggable and Sortable, I will appreciate > > your help. > > Actually, in your specific case (which, I gather, only involved > auto-completion), there are only two event handlers being created when > you do: > > new Ajax.Autocompleter(...); > > - one on blur > - one on keypress > > They both tackle your input field. > > When you replace the DOM fragment that contains your input field (do you > really need to?!), those events never get fired again, because what the > user types in is another field, a new one, created by your > fragment-replacing code (e.g. the processing of a Ajax.Updater, or a > call of yours to Element.replace or Element.update). > > It''s not too bad that you didn''t remove those two event observers; > they''re not going to be triggered, and the garbage collector will handle > them properly. > > However, what you need, at the minimum, is to follow DOM replacement by > an identical call to "new Ajax.Autocompleter(...)", to recreate the > functionality for your new DOM elements. > > Still, the question remains: why on Earth do you replace your > auto-completed field (and its completion zone)? Can''t you do otherwise? > > -- > Christophe Porteneuve a.k.a. TDD > "[They] did not know it was impossible, so they did it." --Mark Twain > Email: tdd-x+CfDp/qHev2eFz/2MeuCQ@public.gmane.org > > > >--~--~---------~--~----~------------~-------~--~----~ 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 rubyonrails-spinoffs-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-spinoffs-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-spinoffs?hl=en -~----------~----~----~----~------~----~------~--~---
I tried to simplify my code in order to post here and to see if someone have time to help me out test.html !DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" " http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> <script src="/javascripts/prototype.js" type="text/javascript"></script> <script src="/javascripts/scriptaculous.js" type="text/javascript"></script> </head> <body> <div id="replace"> <form> <table><tr><td>AA</td><td>BB</td></tr> <tr><td>R11</td><td>R12</td></tr> <tr><td onclick="new Ajax.Request(''/test1.html'', {asynchronous:true, onSuccess: function(t) { $(''replace'').innerHTML=t.responseText;}})">R21</td> <td><input type=text name="test" id="mio"><div id="autoc" class="autocomplete"></div><script type="text/javascript" language="javascript">var pippo=new Ajax.Autocompleter( "mio", "autoc", "/return.html", {});</script> R22</td></tr> <tr><td>R31</td><td>R32</td></tr> </table> </form> </div> test1.html <form> <table><tr><td>AA</td><td>BB</td></tr> <tr><td>R11</td><td>R12</td></tr> <tr><td onclick="new Ajax.Request(''/test1.html'', {asynchronous:true, onSuccess: function(t) { $(''replace'').innerHTML=t.responseText ;}})">R22341</td> <td> <input type=text name="test" id="mio"><div id="autoc" class="autocomplete"></div><script type="text/javascript" language="javascript">var pippo=new Ajax.Autocompleter("mio ", "autoc", "/return.html", {});</script> R22</td></tr> <tr><td>R31</td><td>R32</td></tr> </table> </form> return.html <ul> <li id="1">your mom</li> <li id="2">yodel</li> </ul> If I click on the second row the autocomplete does not work anymore On 12/28/06, Il Neofita <asteriskmail-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> > I will try to explain what I am doing. > > I have a page loaded with a table, when I press in a row the table is > reloaded and in the row that I selected I put the input box. If I do this > the autocompleter does not work. Now, I cannot understand how I can solve > this problem having the new event hadler to point to this new element. > > Thank you > > On 12/28/06, Christophe Porteneuve <tdd-x+CfDp/qHev2eFz/2MeuCQ@public.gmane.org> wrote: > > > > > > Il Neofita a écrit : > > > If do you have time can you explain to me a little bit more, since I > > do > > > not know nothing regarding Draggable and Sortable, I will appreciate > > > your help. > > > > Actually, in your specific case (which, I gather, only involved > > auto-completion), there are only two event handlers being created when > > you do: > > > > new Ajax.Autocompleter(...); > > > > - one on blur > > - one on keypress > > > > They both tackle your input field. > > > > When you replace the DOM fragment that contains your input field (do you > > really need to?!), those events never get fired again, because what the > > user types in is another field, a new one, created by your > > fragment-replacing code ( e.g. the processing of a Ajax.Updater, or a > > call of yours to Element.replace or Element.update). > > > > It''s not too bad that you didn''t remove those two event observers; > > they''re not going to be triggered, and the garbage collector will handle > > > > them properly. > > > > However, what you need, at the minimum, is to follow DOM replacement by > > an identical call to "new Ajax.Autocompleter(...)", to recreate the > > functionality for your new DOM elements. > > > > Still, the question remains: why on Earth do you replace your > > auto-completed field (and its completion zone)? Can''t you do otherwise? > > > > -- > > Christophe Porteneuve a.k.a. TDD > > "[They] did not know it was impossible, so they did it." --Mark Twain > > Email: tdd-x+CfDp/qHev2eFz/2MeuCQ@public.gmane.org > > > > > > > > >--~--~---------~--~----~------------~-------~--~----~ 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 rubyonrails-spinoffs-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-spinoffs-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-spinoffs?hl=en -~----------~----~----~----~------~----~------~--~---
-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 Il Neofita wrote:> test.html > [...] > <td onclick="new Ajax.Request(''/test1.html'', {asynchronous:true, > onSuccess: function(t) { > $(''replace'').innerHTML=t.responseText;}})">R21</td>^ You are not evaluating response scripts, but merely replacing the content of "replace". Call t.responseText.evalScripts() to fix it. A less ugly way would be to use Ajax.Updater instead: <td onclick="new Ajax.Updater(''replace'', ''/test1.html'', {evalScripts:true})">R21</td> (OFC, even less ugly would be to move away all those inline scripts, but that''s already a different story). cheers - -- Marius Feraru -----BEGIN PGP SIGNATURE----- iD8DBQFFlI8ttZHp/AYZiNkRAv2rAKCQwj8+i6ETuWzDY6MQqBWYwSH99ACg55HG A7b9PISx9tuduOdTqxE8je0=Cgci -----END PGP SIGNATURE----- --~--~---------~--~----~------------~-------~--~----~ 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 rubyonrails-spinoffs-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-spinoffs-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-spinoffs?hl=en -~----------~----~----~----~------~----~------~--~---
Thank you. For the inline instruction I find easier to check the code for this learning phase On 12/28/06, Marius Feraru <altblue-9gptZ63fvgw@public.gmane.org> wrote:> > > -----BEGIN PGP SIGNED MESSAGE----- > Hash: SHA1 > > Il Neofita wrote: > > test.html > > [...] > > <td onclick="new Ajax.Request(''/test1.html'', {asynchronous:true, > > onSuccess: function(t) { > > $(''replace'').innerHTML=t.responseText;}})">R21</td> > ^ You are not evaluating response scripts, but merely replacing the > content of "replace". Call t.responseText.evalScripts() to fix it. > > A less ugly way would be to use Ajax.Updater instead: > > <td onclick="new Ajax.Updater(''replace'', ''/test1.html'', > {evalScripts:true})">R21</td> > > (OFC, even less ugly would be to move away all those inline scripts, but > that''s already a different story). > > cheers > - -- > Marius Feraru > -----BEGIN PGP SIGNATURE----- > > iD8DBQFFlI8ttZHp/AYZiNkRAv2rAKCQwj8+i6ETuWzDY6MQqBWYwSH99ACg55HG > A7b9PISx9tuduOdTqxE8je0> =Cgci > -----END PGP SIGNATURE----- > > > >--~--~---------~--~----~------------~-------~--~----~ 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 rubyonrails-spinoffs-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-spinoffs-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-spinoffs?hl=en -~----------~----~----~----~------~----~------~--~---