Solved without jquery

       if form.accepts(request.vars, session):
             row = db.cronograma_desembolso[form.vars.id]
             total = row.valor_custeio_concedente +
row.valor_investimento_concedente + row.valor_custeio_contrapartida +
row.valor_investimento_contrapartida
             row.update_record(valor_total = total)

2010/1/14 mdipierro <[email protected]>

> Try Field('total','double') (compute=None, writable=True,
> readable=True) and
>
> jQuery("input[name='quantity'],input[name='price']").keyup(function()
> {
> jQuery("input[name='total']").val(parseFloat(jQuery("input
> [name='price']").val())*parseInt(jQuery("input[name='quantity']"));
> });
>
> Use firebug in to debug the JS. compute should not be used if the
> field is shown.
>
> On Jan 14, 2:18 pm, Alexandre Andrade <[email protected]>
> wrote:
> > 1. The total is not showed when editing. I don't need in this moment.
> When I
> > set .compute, its hide (like writable=False and readable=False) the field
> in
> > the form.
> > 2. the main problem is .compute is not inserting/updating the field on
> db,
> > and neither acting as represent when showing
> >
> > 2010/1/14 mdipierro <[email protected]>
> >
> >
> >
> > > I see the problem. I can find a way around it but I feel it would be
> > > wrong.
> >
> > > When you submit a form, what you see is what should go in the DB, even
> > > if some fields are readonly.
> >
> > > If you have quantity, price and total you should not display the same
> > > total that is in DB before submission as readonly, because has you
> > > change quantity or price the total should change but it does not. To a
> > > user this is confusing. To the user it looks like they submit a form
> > > with the wrong total (the previous one, not the one reflacing the
> > > change in the other fields).
> >
> > > You should not use compute.
> >
> > > You should use JS
> >
> > > <script>
> > > jQuery("input[name='quantity'],input[name='price']").change(function()
> > > {
> > > jQuery("input[name='total']").val(parseFloat(jQuery("input
> > > [name='price']").val())*parseInt(jQuery("input[name='quantity']"));
> > > });
> > > </script>
> >
> > > when use a custom validator to make sure the user did not mess up this
> > > field somehow.
> > > there are many options.
> >
> > > On Jan 14, 12:57 pm, Alexandre Andrade <[email protected]>
> > > wrote:
> > > > It don't show at form, without readable=False.
> >
> > > > I set readable=False, but it don't show the updated value.
> >
> > > > 2010/1/14 mdipierro <[email protected]>
> >
> > > > > Can you also try set readable=False?
> >
> > > > > On Jan 14, 9:52 am, mdipierro <[email protected]> wrote:
> > > > > > Make sure Field(...,default=None, update=None)
> >
> > > > > > On Jan 14, 9:47 am, Alexandre Andrade <[email protected]>
> > > > > > wrote:
> >
> > > > > > > db.order_detail.total.compute=lambda r: r['qtd']*r['price']
> >
> > > > > > > don't work on updates
> >
> > > > > > > 2010/1/14 mdipierro <[email protected]>
> >
> > > > > > > > with 1.74.5 and later you only need
> >
> > > > > > > > db.order_detail.total.compute=lambda r: r['qtd']*r['price']
> >
> > > > > > > > On Jan 14, 8:51 am, Alexandre Andrade <
> [email protected]>
> > > > > > > > wrote:
> > > > > > > > > What is the best solution to automatically calculate a
> total
> > > field?
> >
> > > > > > > > > db.define_table ('order_detail',
> > > > > > > > >               Field('product_name'),
> > > > > > > > >               Field('qtd', 'integer'),
> > > > > > > > >               Field('price', 'integer'),
> > > > > > > > >               Field('total', 'integer', writable=False)
> > > > > > > > > )
> >
> > > > > > > > > Where  total = qtd * price
> >
> > > > > > > > > requires and a custom validator? how to do?
> > > > > > > > > onvalidation on form? how to do?
> >
> > > > > > > > > --
> > > > > > > > > Atenciosamente
> >
> > > > > > > > > --
> > > > > > > > > =========================
> > > > > > > > > Alexandre Andrade
> > > > > > > > > Hipercenter.com
> >
> > > > > > > > --
> > > > > > > > You received this message because you are subscribed to the
> > > Google
> > > > > Groups
> > > > > > > > "web2py-users" group.
> > > > > > > > To post to this group, send email to [email protected]
> .
> > > > > > > > To unsubscribe from this group, send email to
> > > > > > > > [email protected]<web2py%[email protected]>
> <web2py%[email protected]<web2py%[email protected]>
> >
> > > <web2py%[email protected]<web2py%[email protected]>
> <web2py%[email protected]<web2py%[email protected]>
> >
> >
> > > > > <web2py%[email protected]<web2py%[email protected]>
> <web2py%[email protected]<web2py%[email protected]>
> >
> > > <web2py%[email protected]<web2py%[email protected]>
> <web2py%[email protected]<web2py%[email protected]>
> >
> >
> > > > > > > > .
> > > > > > > > For more options, visit this group at
> > > > > > > >http://groups.google.com/group/web2py?hl=en.
> >
> > > > > > > --
> > > > > > > Atenciosamente
> >
> > > > > > > --
> > > > > > > =========================
> > > > > > > Alexandre Andrade
> > > > > > > Hipercenter.com
> >
> > > > > --
> > > > > You received this message because you are subscribed to the Google
> > > Groups
> > > > > "web2py-users" group.
> > > > > To post to this group, send email to [email protected].
> > > > > To unsubscribe from this group, send email to
> > > > > [email protected]<web2py%[email protected]>
> <web2py%[email protected]<web2py%[email protected]>
> >
> > > <web2py%[email protected]<web2py%[email protected]>
> <web2py%[email protected]<web2py%[email protected]>
> >
> >
> > > > > .
> > > > > For more options, visit this group at
> > > > >http://groups.google.com/group/web2py?hl=en.
> >
> > > > --
> > > > Atenciosamente
> >
> > > > --
> > > > =========================
> > > > Alexandre Andrade
> > > > Hipercenter.com
> >
> > > --
> > > You received this message because you are subscribed to the Google
> Groups
> > > "web2py-users" group.
> > > To post to this group, send email to [email protected].
> > > To unsubscribe from this group, send email to
> > > [email protected]<web2py%[email protected]>
> <web2py%[email protected]<web2py%[email protected]>
> >
> > > .
> > > For more options, visit this group at
> > >http://groups.google.com/group/web2py?hl=en.
> >
> > --
> > Atenciosamente
> >
> > --
> > =========================
> > Alexandre Andrade
> > Hipercenter.com
>
> --
> You received this message because you are subscribed to the Google Groups
> "web2py-users" group.
> To post to this group, send email to [email protected].
> To unsubscribe from this group, send email to
> [email protected]<web2py%[email protected]>
> .
> For more options, visit this group at
> http://groups.google.com/group/web2py?hl=en.
>
>
>
>


-- 
Atenciosamente

-- 
=========================
Alexandre Andrade
Hipercenter.com
--
You received this message because you are subscribed to the Google Groups "web2py-users" 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/web2py?hl=en.

Reply via email to