# Intermediate Form Calculation

**URL:** <https://www.ruby-forum.com/t/intermediate-form-calculation/84089>\
**Category:** Rails\
**Created:** [February 1, 2007, 10:46am UTC](https://www.ruby-forum.com/t/intermediate-form-calculation/84089 "2007-02-01T10:46:03Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![khmckgrp](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/ac8455/32.png) [@khmckgrp](https://www.ruby-forum.com/u/khmckgrp)\
**Post date:** [February 1, 2007, 10:46am UTC](https://www.ruby-forum.com/t/intermediate-form-calculation/84089/1 "2007-02-01T10:46:03Z")

</div>

I have a form that includes some filtering criteria (select customers  
based on age, sex, status, etc). I want to add a ‘calculate’ button on  
the form which will go off and calculate, then display, how many  
customers will be included in the selection. I want the user to be able  
to amend the filtering until they are happy with the numbers, without  
having to submit the form and go back if the numbers are not right.

If there was only one filter (ie one field value), I would user an  
observer and in the controller use request.raw\_post to get the single  
value to apply to the query. However as there are several form fields  
required, I cannot see how I can access them without first submitting  
the form.

---

<div class="post-metadata">

**Author:** ![khmckgrp](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/ac8455/32.png) [@khmckgrp](https://www.ruby-forum.com/u/khmckgrp)\
**Post date:** [February 1, 2007, 11:38am UTC](https://www.ruby-forum.com/t/intermediate-form-calculation/84089/2 "2007-02-01T11:38:01Z")

</div>

Kevin Hankinson wrote:

> I have a form that includes some filtering criteria (select customers  
> based on age, sex, status, etc). I want to add a ‘calculate’ button on  
> the form which will go off and calculate, then display, how many  
> customers will be included in the selection. I want the user to be able  
> to amend the filtering until they are happy with the numbers, without  
> having to submit the form and go back if the numbers are not right.

If you can accept a link instead of the button, then:

link\_to\_remote ‘calculate’, :url=\>{:action=\>‘calculate’},:with =\>  
“Form.serialize(‘your\_form\_id’)”

Regards  
Massimo  
[http://www.addsw.it](http://www.addsw.it)

---

<div class="post-metadata">

**Author:** ![khmckgrp](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/ac8455/32.png) [@khmckgrp](https://www.ruby-forum.com/u/khmckgrp)\
**Post date:** [February 1, 2007, 2:29pm UTC](https://www.ruby-forum.com/t/intermediate-form-calculation/84089/3 "2007-02-01T14:29:14Z")

</div>

Massimo wrote:

> Kevin Hankinson wrote:
> 
> > I have a form that includes some filtering criteria (select customers  
> > based on age, sex, status, etc). I want to add a ‘calculate’ button on  
> > the form which will go off and calculate, then display, how many  
> > customers will be included in the selection. I want the user to be able  
> > to amend the filtering until they are happy with the numbers, without  
> > having to submit the form and go back if the numbers are not right.
> 
> If you can accept a link instead of the button, then:
> 
> link\_to\_remote ‘calculate’, :url=\>{:action=\>‘calculate’},:with =\>  
> “Form.serialize(‘your\_form\_id’)”
> 
> Regards  
> Massimo  
> [http://www.addsw.it](http://www.addsw.it)

thanks for this. Ideally i want to use a form observer:

\<%= observe\_field(:groups, :frequency=\> 0.5, :update=\> :totalCustomers,  
:url=\>{:action=\>:total\_in\_group}, :with=\>“Form.serialize(‘newAdvert’)”,  
:loading=\>“Element.show(‘progress1’)”,  
:complete=\>“Element.hide(‘progress1’)”) %\>

However, I get a javascript error: Error: Expected }

‘newAdvert’ is the name of my form

It goes away if i remove the :with parameter.

Can anyone spot the mistake?

---

<div class="post-metadata">

**Author:** ![khmckgrp](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/ac8455/32.png) [@khmckgrp](https://www.ruby-forum.com/u/khmckgrp)\
**Post date:** [February 1, 2007, 3:57pm UTC](https://www.ruby-forum.com/t/intermediate-form-calculation/84089/4 "2007-02-01T15:57:14Z")

</div>

Massimo wrote:

> > thanks for this. Ideally i want to use a form observer:
> > 
> > \<%= observe\_field(:groups, :frequency=\> 0.5, :update=\> :totalCustomers,  
> > :url=\>{:action=\>:total\_in\_group}, :with=\>“Form.serialize(‘newAdvert’)”,  
> > :loading=\>“Element.show(‘progress1’)”,  
> > :complete=\>“Element.hide(‘progress1’)”) %\>
> 
> With observe\_field, I think you need  
> :with=\>“form=Form.serialize(‘newAdvert’)”
> 
> > ‘newAdvert’ is the name of my form
> 
> newAdvert must be the form ID (form name is not important). Check your  
> html source.

thanks for pointing this out. Unfortunately, still getting the js error.

```
     Expected '}'

```

Taking the single qoutes off the form id (‘newAdvert’) resolves the js  
error, but obviously breaks the form serialising when we get to the  
controller

---

<div class="post-metadata">

**Author:** ![khmckgrp](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/ac8455/32.png) [@khmckgrp](https://www.ruby-forum.com/u/khmckgrp)\
**Post date:** [February 1, 2007, 2:49pm UTC](https://www.ruby-forum.com/t/intermediate-form-calculation/84089/5 "2007-02-01T14:49:00Z")

</div>

> thanks for this. Ideally i want to use a form observer:
> 
> \<%= observe\_field(:groups, :frequency=\> 0.5, :update=\> :totalCustomers,  
> :url=\>{:action=\>:total\_in\_group}, :with=\>“Form.serialize(‘newAdvert’)”,  
> :loading=\>“Element.show(‘progress1’)”,  
> :complete=\>“Element.hide(‘progress1’)”) %\>

With observe\_field, I think you need  
:with=\>“form=Form.serialize(‘newAdvert’)”

> ‘newAdvert’ is the name of my form

newAdvert must be the form ID (form name is not important). Check your  
html source.

---

<div class="post-metadata">

**Author:** ![khmckgrp](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/ac8455/32.png) [@khmckgrp](https://www.ruby-forum.com/u/khmckgrp)\
**Post date:** [January 21, 2008, 4:46am UTC](https://www.ruby-forum.com/t/intermediate-form-calculation/84089/6 "2008-01-21T04:46:55Z")

</div>

Hello Massimo,

Try this way, maybe it’s worth:

\<%=observe\_field(:groups, :frequency=\>0.5, :update=\> :totalCustomers,  
:url=\> { :action =\>  
“total\_in\_group” }, :with=\>“Form.serialize(‘newAdvert’)”,  
:loading=\>“Element.show(‘progress1’)”,  
:complete=\>“Element.hide(‘progress1’)”) %\>

I’ve a observe\_field and this way is ok --\> :url =\> { :action =\>  
“total\_in\_group” }

I need help to make observe\_field of group of input. How do you make  
this in the controller and in the view?

,thanks!

On 1 fev 2007, 12:57, Kevin Hankinson \<rails-mailing-l…@andreas-
