Intermediate Form Calculation

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.

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

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

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?

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

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.

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-