# Observe\_form question

**URL:** <https://www.ruby-forum.com/t/observe-form-question/149917>\
**Category:** Rails\
**Created:** [October 1, 2008, 6:29am UTC](https://www.ruby-forum.com/t/observe-form-question/149917 "2008-10-01T06:29:34Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![hangingclowns](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/h/b5e925/32.png) [@hangingclowns](https://www.ruby-forum.com/u/hangingclowns)\
**Post date:** [October 1, 2008, 6:29am UTC](https://www.ruby-forum.com/t/observe-form-question/149917/1 "2008-10-01T06:29:34Z")

</div>

Ok in my view.rhtml:

\<% form\_for :sale, :url =\> {:action =\> ‘add\_sale’, :id =\> @report},  
:html =\> {:id =\> ‘sales\_form’} do |f| %\>  
…  
\<%= f.text\_field :unit\_price, :size =\> 10 %\>  
…  
\<% end %\>

\<%= observe\_form( :sales\_form, :url =\> {:action =\> “update\_sales\_form”},  
:update =\> :sale\_unit\_price) %\>

and in my controller:

def update\_sales\_form  
render :text =\> “100”  
end

* * *

Now when i make a change to the form (click around, etc), it is calling  
“update\_sales\_form”. But apparently I’m confused as to how to update the  
“unit\_price” element in the DOM.

Thanks for any help

---

<div class="post-metadata">

**Author:** ![hangingclowns](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/h/b5e925/32.png) [@hangingclowns](https://www.ruby-forum.com/u/hangingclowns)\
**Post date:** [October 1, 2008, 8:18am UTC](https://www.ruby-forum.com/t/observe-form-question/149917/2 "2008-10-01T08:18:42Z")

</div>

On Wed, Oct 1, 2008 at 2:29 PM, Allen W.  
[removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> \<%= observe\_form( :sales\_form, :url =\> {:action =\> “update\_sales\_form”},  
> :update =\> :sale\_unit\_price) %\>

> Now when i make a change to the form (click around, etc), it is calling  
> “update\_sales\_form”. But apparently I’m confused as to how to update the  
> “unit\_price” element in the DOM.

Did you mean to type:

\<%= observe\_form( :sales\_form, :url =\> {:action =\>  
“update\_sales\_form”},  
:update =\> :unit\_price) %\>  
^^^^^^^^^^^^^^^^^^^^^^^^^

unit\_price not sale\_unit\_price ?

Mikel

–

> **[Mikel Lindsaar](https://lindsaar.net/)**
>
> Internet Home for Mikel Lindsaar

Rails, RSpec and Life blog…

---

<div class="post-metadata">

**Author:** ![hangingclowns](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/h/b5e925/32.png) [@hangingclowns](https://www.ruby-forum.com/u/hangingclowns)\
**Post date:** [October 1, 2008, 9:08am UTC](https://www.ruby-forum.com/t/observe-form-question/149917/3 "2008-10-01T09:08:10Z")

</div>

Well I’ve tried both and it doesn’t work. My generated html source for  
the form:

Mikel L. wrote:

> On Wed, Oct 1, 2008 at 2:29 PM, Allen W.  
> [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:
> 
> > \<%= observe\_form( :sales\_form, :url =\> {:action =\> “update\_sales\_form”},  
> > :update =\> :sale\_unit\_price) %\>
> 
> > Now when i make a change to the form (click around, etc), it is calling  
> > “update\_sales\_form”. But apparently I’m confused as to how to update the  
> > “unit\_price” element in the DOM.
> 
> Did you mean to type:
> 
> \<%= observe\_form( :sales\_form, :url =\> {:action =\>  
> “update\_sales\_form”},  
> :update =\> :unit\_price) %\>  
> ^^^^^^^^^^^^^^^^^^^^^^^^^
> 
> unit\_price not sale\_unit\_price ?
> 
> Mikel
> 
> –  
> [http://lindsaar.net/](http://lindsaar.net/)  
> Rails, RSpec and Life blog…

---

<div class="post-metadata">

**Author:** ![hangingclowns](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/h/b5e925/32.png) [@hangingclowns](https://www.ruby-forum.com/u/hangingclowns)\
**Post date:** [October 1, 2008, 10:06am UTC](https://www.ruby-forum.com/t/observe-form-question/149917/4 "2008-10-01T10:06:30Z")

</div>

On Oct 1, 8:08 am, Allen W. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
wrote:

> Well I’ve tried both and it doesn’t work. My generated html source for  
> the form:

The :update option isn’t going to do much since it replaces the inner  
html for the tag and an input tag has no inner html. Executing some  
javascript along the lines of $(‘sale\_unit\_price’).value = … should  
do the trick

Fred

---

<div class="post-metadata">

**Author:** ![hangingclowns](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/h/b5e925/32.png) [@hangingclowns](https://www.ruby-forum.com/u/hangingclowns)\
**Post date:** [October 1, 2008, 6:53pm UTC](https://www.ruby-forum.com/t/observe-form-question/149917/5 "2008-10-01T18:53:27Z")

</div>

Ok … so how exactly should I code this in my controller method? Also  
you are suggesting I should not have the :update option at all in my  
observe\_form call?

Frederick C. wrote:

> On Oct 1, 8:08ï¿½am, Allen W. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
> wrote:
> 
> > Well I’ve tried both and it doesn’t work. My generated html source for  
> > the form:
> 
> The :update option isn’t going to do much since it replaces the inner  
> html for the tag and an input tag has no inner html. Executing some  
> javascript along the lines of $(‘sale\_unit\_price’).value = … should  
> do the trick
> 
> Fred

---

<div class="post-metadata">

**Author:** ![hangingclowns](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/h/b5e925/32.png) [@hangingclowns](https://www.ruby-forum.com/u/hangingclowns)\
**Post date:** [October 1, 2008, 7:48pm UTC](https://www.ruby-forum.com/t/observe-form-question/149917/6 "2008-10-01T19:48:45Z")

</div>

In my controller I tried:

render :text =\> “$(‘sale\_unit\_price’).value = 100”

no such luck

Allen W. wrote:

> Ok … so how exactly should I code this in my controller method? Also  
> you are suggesting I should not have the :update option at all in my  
> observe\_form call?
> 
> Frederick C. wrote:
> 
> > On Oct 1, 8:08ï¿½am, Allen W. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
> > wrote:
> > 
> > > Well I’ve tried both and it doesn’t work. My generated html source for  
> > > the form:
> > 
> > The :update option isn’t going to do much since it replaces the inner  
> > html for the tag and an input tag has no inner html. Executing some  
> > javascript along the lines of $(‘sale\_unit\_price’).value = … should  
> > do the trick
> > 
> > Fred

---

<div class="post-metadata">

**Author:** ![hangingclowns](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/h/b5e925/32.png) [@hangingclowns](https://www.ruby-forum.com/u/hangingclowns)\
**Post date:** [October 1, 2008, 7:51pm UTC](https://www.ruby-forum.com/t/observe-form-question/149917/7 "2008-10-01T19:51:49Z")

</div>

Ok I got it to work doing:

render :update do |page|  
page \<\< “$(‘sale\_unit\_price’).value = 100;”  
end

---

<div class="post-metadata">

**Author:** ![hangingclowns](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/h/b5e925/32.png) [@hangingclowns](https://www.ruby-forum.com/u/hangingclowns)\
**Post date:** [October 1, 2008, 7:56pm UTC](https://www.ruby-forum.com/t/observe-form-question/149917/8 "2008-10-01T19:56:47Z")

</div>

That won’t work unless you’ve removed the :update option from your  
observe form (and probably won’t work then since I seem to remember  
that prototype checks the content type of the response). An rjs (or  
js.erb) template or a render :update block would take care of that.

Fred

Sent from my iPhone

On 1 Oct 2008, at 18:48, Allen W. \<rails-mailing-list@andreas-
