# Ajax InPlaceEditor

**URL:** <https://www.ruby-forum.com/t/ajax-inplaceeditor/84436>\
**Category:** Rails\
**Created:** [February 4, 2007, 4:16pm UTC](https://www.ruby-forum.com/t/ajax-inplaceeditor/84436 "2007-02-04T16:16:05Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![kadoudal](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/f0a364/32.png) [@kadoudal](https://www.ruby-forum.com/u/kadoudal)\
**Post date:** [February 4, 2007, 4:16pm UTC](https://www.ruby-forum.com/t/ajax-inplaceeditor/84436/1 "2007-02-04T16:16:05Z")

</div>

tseting an InPlaceEditor, I am trying the :onComplete option (code to  
be run, if update successful with server)  
even not fleunt with JS, I succeeded with an Ajax.Request

onComplete: function(transport,element) { new  
Ajax.Request(’/profils/change\_domain\_category/’, {asynchronous:true,  
evalScripts:true, parameters:‘new\_domain\_name=’ +  
this.element.childNodes[0].nodeValue + ‘&old\_domain\_key=’ + ‘#{value}’  
});return false;},

I am trying a simpler function to remove a class name from the current  
element :

onComplete: function(transport,element){ new  
removeClassName(this.element, ‘red’); }"

but it’s wrong… I got an error ( invalid property id) why ? how  
should I write it correctly ?

thansk fyl

kad

---

<div class="post-metadata">

**Author:** ![kadoudal](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/f0a364/32.png) [@kadoudal](https://www.ruby-forum.com/u/kadoudal)\
**Post date:** [February 4, 2007, 4:49pm UTC](https://www.ruby-forum.com/t/ajax-inplaceeditor/84436/2 "2007-02-04T16:49:47Z")

</div>

Kad K. wrote:

> tseting an InPlaceEditor,

Please write automated tests for it, too… 😉

> I am trying the :onComplete option (code to  
> be run, if update successful with server)  
> even not fleunt with JS, I succeeded with an Ajax.Request
> 
> onComplete: function(transport,element) { new  
> Ajax.Request(‘/profils/change\_domain\_category/’, {asynchronous:true,  
> evalScripts:true, parameters:‘new\_domain\_name=’ +  
> this.element.childNodes[0].nodeValue + ‘&old\_domain\_key=’ + ‘#{value}’  
> });return false;},

Tip: Put into your View a hidden field (using link\_to\_remote), and  
use  
onComplete to trigger it, with something like onComplete: function() {  
$(‘my\_anchor\_id’).onclick(); }. I don’t know if that would work, but I  
would  
start there, and it puts as much Ajax inside Ruby helper-generators as  
possible.

 

And I think you can lose the ‘transport,element’ if you are not using  
it…

 

> I am trying a simpler function to remove a class name from the current  
> element :
> 
> onComplete: function(transport,element){ new  
> removeClassName(this.element, ‘red’); }"
> 
> but it’s wrong… I got an error ( invalid property id) why ? how  
> should I write it correctly ?

 

What’s ‘this’ at the time onComplete runs? Who runs onComplete?

 

Try $(‘my\_explicit\_id’).

 

–  
Phlip  
 [Redirecting...](http://www.greencheese.us/ZeekLand) ← NOT a blog!!!

---

<div class="post-metadata">

**Author:** ![kadoudal](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/f0a364/32.png) [@kadoudal](https://www.ruby-forum.com/u/kadoudal)\
**Post date:** [February 4, 2007, 6:54pm UTC](https://www.ruby-forum.com/t/ajax-inplaceeditor/84436/3 "2007-02-04T18:54:54Z")

</div>

> And I think you can lose the ‘transport,element’ if you are not using it… YES, THANKS
> 
> > I am trying a simpler function to remove a class name from the current  
> > element :
> > 
> > onComplete: function(transport,element){ new  
> > removeClassName(this.element, ‘red’); }"
> > 
> > but it’s wrong… I got an error ( invalid property id) why ? how  
> > should I write it correctly ?
> 
> What’s ‘this’ at the time onComplete runs? Who runs onComplete?

I have 2 dropdown selectors ‘domain’ and ‘category’, each one handled by  
specific in\_place\_collection\_editor helpers

1- in\_place\_domain\_editor(container, value = nil)  
url =\> set\_proposal\_domain # which return the selected domain name  
onComplete: AjaxRequest… :action =\> change\_domain\_category  
parameters:‘new\_domain\_name=’ + this.element.childNodes[0].nodeValue

change\_domain\_category renders via → change\_domain\_category.rjs :  
page.remove ‘category\_selector’ #remove old category selector  
page.insert\_html :after, ‘domain\_selector’, :partial =\>  
‘category\_selector’ #insert new category selector based on new domain  
page.replace\_html ‘category’ , ‘choose category…’ #no category  
selected yet, return text  
page[‘category’].add\_className(‘red’) # set in\_place\_category\_editor  
to class .red

2- in\_place\_category\_editor(container, value = nil)  
url =\> set\_proposal\_category # which return the selected domain name  
obviously the ‘category’ DOM element has class .red, but onComplete  
this class should be removed

that’s why I would like to use onComplete: option in this  
in\_place\_category\_editor

Here is the view  
…

\<%= my\_prop.category.domain.name %\> \<%= in\_place\_domain\_editor(domains, domain\_selected) %\>

\<%= my\_prop.category.name %\> \<%= in\_place\_category\_editor(categories, category\_selected) %\>

> Try $(‘my\_explicit\_id’).  
> I tried , unsuccessfully
> 
> –  
> Phlip  
> [Redirecting...](http://www.greencheese.us/ZeekLand) ← NOT a blog!!!

---

<div class="post-metadata">

**Author:** ![kadoudal](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/f0a364/32.png) [@kadoudal](https://www.ruby-forum.com/u/kadoudal)\
**Post date:** [February 4, 2007, 7:30pm UTC](https://www.ruby-forum.com/t/ajax-inplaceeditor/84436/4 "2007-02-04T19:30:04Z")

</div>

Kad K. wrote:

> > > onComplete: function(transport,element){ new  
> > > removeClassName(this.element, ‘red’); }"
> > > 
> > > but it’s wrong… I got an error ( invalid property id) why ? how  
> > > should I write it correctly ?
> > 
> > What’s ‘this’ at the time onComplete runs? Who runs onComplete?
> 
> I have 2 dropdown selectors ‘domain’ and ‘category’, each one handled by  
> specific in\_place\_collection\_editor helpers

How do you know they are ‘this’? I suspect that a setTimeout() runs  
onComplete, so ‘this’ might not be what you expect. Or maybe it is; add  
alert(this) to see.

> > Try $(‘my\_explicit\_id’).

> I tried , unsuccessfully

Try again; it’s better than ‘this’. And can’t removeClassName just take  
a  
string?

–  
Phlip  
[Redirecting...](http://www.greencheese.us/ZeekLand) ← NOT a blog!!!

---

<div class="post-metadata">

**Author:** ![kadoudal](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/f0a364/32.png) [@kadoudal](https://www.ruby-forum.com/u/kadoudal)\
**Post date:** [February 4, 2007, 9:54pm UTC](https://www.ruby-forum.com/t/ajax-inplaceeditor/84436/5 "2007-02-04T21:54:24Z")

</div>

> Try again; it’s better than ‘this’. And can’t removeClassName just take  
> a  
> string?
> 
> –  
> Phlip  
> [Redirecting...](http://www.greencheese.us/ZeekLand) ← NOT a blog!!!

It’s up and running… problem ? 2 commas in the script !!!

"function(resp){ new Element.removeClassName(‘category’, ‘red’); }

I have 2 linked InPlaceCollectionEditor dropdown menu
