Hi Sergio

I think that I understand what you mean, I guess though that my
question was not very clear. Let me explain what I would (ideally)
like to do:
1) When a given field A changes, I invoke a rails helper method
passing the record information with all the filled fields so far (say
A and B)
2) In that helper I carry out a series of calculations involving
several fields of the record, not just the changed column (say C =
A*B)
3) I use the number_to_currency helper method to format the result
4) The value of the calculated field is rendered back in the form

Is that possible? I understand I can render the values of the form
through javascript/AJAX, but in that case I need to format the result
"by hand", as opposed to using number_to_currency helper method, which
automatically takes into account my localization setup.

Thanks in advance for your patience
Pedro

On Mar 22, 9:50 am, "Sergio Cambra .:: entreCables S.L. ::."
<[email protected]> wrote:
> On Viernes, 19 de Marzo de 2010 21:45:00 Pedro G. escribió:
>
>
>
>
>
> > Thanks a lot, Sergio
>
> > I'm almost there, the problem is that I'm still facing is the
> > following one: I want to update the net_amount column in my model
> > whenever the amount column or the vat column changes in the following
> > way: net_amount = amount * (1.0 + vat/100.0). The amount column is
> > formatted in the form as a currency.
>
> > To this purpose I overrode render_field.js.rjs as you said (with minor
> > modifications):
>
> > page <<render(:super)
> > net_amount_id =
> > active_scaffold_input_options(active_scaffold_config.columns[:net_amount],
> > params[:scope])[:id]
> > amount_id =
> > active_scaffold_input_options(active_scaffold_config.columns[:amount],
> > params[:scope])[:id]
> > vat_id =
> > active_scaffold_input_options(active_scaffold_config.columns[:vat],
> > params[:scope])[:id]
> > page << "$('#{net_amount_id}').value =
> > $F('#{amount_id}').gsub(',','.').gsub('€','') * (1.0 + $F('#{vat_id}')/
> > 100.0)" + ' €'"
>
> > I can't use @record.amount since this can be called when the vat
> > column is modified, and then I don't have that value. The gsubs in the
> > last line are hideous, but that gets rid of the separator and the
> > currency symbol in amount (please let me know if you can think of a
> > more elegant way of doing this)
>
> > The problem is that I can't figure out how to display back that value
> > in the form as a currency (in Spanish format, that is 1,23 €) in a
> > similar fashion to what number_to_currency would display.
>
> If you don't need to change HTML, it would be better to use only JS without
> AJAX request, without using update_column. Make a JS function and bind
> onchange event of those fields using JS or setting onchange in
> config.columns[:column_name].options.
>
>
>
>
>
>
>
> > On Mar 19, 10:30 am, "Sergio Cambra .:: entreCables S.L. ::."
>
> > <[email protected]> wrote:
> > > On Viernes, 19 de Marzo de 2010 01:13:30 Pedro G. escribió:
> > > > Hi,
>
> > > > I have the following situation that I've been unable to solve
> > > > succesfully: in one of the columns of my controller I have defined the
> > > > following
> > > >     config.columns[:units].options = {:update_column => :amount}
>
> > > > Basically I want to update the value of the amount column based on the
> > > > values of the units column plus another column of the record. However,
> > > > in the after_render_field(record, column) method I don't have access
> > > > to other fields in record apart from units.
>
> > > > ¿Is there any way to overcome this?
> > > > Thanks in advance
> > > > Pedro
>
> > > If you want to use the value in the form, you can override
> > > render_field.js.rjs in your controller views directory as:
>
> > > page <<render(:super)
> > > amount_id = active_scaffold_input_options(:amount, params[:scope])[:id]
> > > field_id = active_scaffold_input_options(column, params[:scope])[:id]
> > > page << "$('#{amount_id}').value = $F('#{field_id}') +
> > > '[email protected]}'
>
> > > --
> > > Sergio Cambra .:: entreCables S.L. ::.
> > > Mariana Pineda 23, 50.018 Zaragoza
> > > T) 902 021 404 F) 976 52 98 07 E) [email protected]
>
> --
> Sergio Cambra .:: entreCables S.L. ::.
> Mariana Pineda 23, 50.018 Zaragoza
> T) 902 021 404 F) 976 52 98 07 E) [email protected]

-- 
You received this message because you are subscribed to the Google Groups 
"ActiveScaffold : Ruby on Rails plugin" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/activescaffold?hl=en.

Reply via email to