views:

82

answers:

2

Trying to put in field "pagar" the calculated value of "precio" * 15% but I don't know why it is not working :S

<% form_for @libro, :html => { :multipart => true } do |f| %>
<%= f.label "Precio (si es venta):" %>
<%= f.text_field :precio %>
<%= observe_field :libro_precio, 
    :frequency => 0.25,
    :update => :libro_pagar,
    :with => 'value*0.15'
%>

<%= f.label "A pagar (si es venta):" %>
<%= f.text_field :pagar %>
<% end %>
+1  A: 

observe_field makes AJAX requests by default. I think you don't need an AJAX here, so use smth like:

<%= observe_field :libro_precio, 
    :frequency => 0.25,
    :update => :libro_pagar,
    :function =>"$('libro_pagar').value = $F('libro_precio')*1.15"
%>
zed_0xff
That made it work! Thank you very much :D
miligraf
A: 

What if I want to add a conditional inside the :fuction?

I just want to evaluate the value of "paciente_genero_id" and if its 1 then it will show the content inside the and if its 2 then it will hide it.

What I have is this

<%= observe_field 'paciente_genero_id',
    :function => update_page {|page| if ($('paciente_genero_id').value==1) { page[:femenino].show } else { page[:femenino].hide } } %>
miligraf