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.
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]
--
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.