silverweb
2008-Feb-09 16:53 UTC
prototype 1.6.0.2 - insert - how to dynamically create parameters?
Hi! (For the first time on the list! ;) ). I tried to create some method, that is added to all form elements, and simply puts an error message near desired element. I wanted the function to look like this: JS: -------------------------- Form.Element.Methods.putError=function(element, msg, insertn) { if (!msg.length) return; insertn=insertn||''after''; msg=''<span class="errorMsg">''+msg+''</span>''; var e=$(element); var err=e.next(".errorMsg"); if (err!=undefinederr.remove(); e.insert({insertn: msg}); }; Element.addMethods(); ----------------------------------- The method is called from ''blur'' observer (for some input field) with something like this inside: if ($F(e)!=$F(h)) e.putError(''This is my error message!''); After I run the page, everything is fine, until it comes to the line e.insert({insertn: msg}); in my putError function... I checked it out and insertn==''after'' and msg==''This is my error message''. Bu in FireBug console I get an error: insert has no properties http://mywebpage.address.com/script/prototype.js Line 1644 More detailed info: insert(input#ponowhaslo.haslo, Object)prototype.js (line 1644) _methodized()prototype.js (line 246) (no name)(input#ponowhaslo.haslo, "<span class="errorMsg">Podaj hasło (conajmniej 4 znaki)</span>", "after")prototype.js (line 426) _methodized()prototype.js (line 246) checkHaslo(input#ponowhaslo.haslo)prototype.js (line 409) wrapper(blur ) When instead of insertn I use ''before''/''after''/etc. when executing e.insert() - everything is fine. But I wanted it to be more flexible. So I tried to use Hash, to pass it to insert(), but nothing happened: var h=new Hash(); h.set(insertn, msg); e.insert(h); I even tried: e.insert(h.toJSON()); but nothing happened too... Also using Element.insert(...); has not worked. Finally I had to use switch/case statement with deprecated Insertion.Before/After/Top/Bottom instead of insert(), and it works great, but it''s deprecated... QUESTION: What is wrong? How should I do this, to make it work as flexible as it should? --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---