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 <alexandrema...@gmail.com>
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 <mdipie...@cs.depaul.edu>
>
>
>
> > Can you also try set readable=False?
>
> > On Jan 14, 9:52 am, mdipierro <mdipie...@cs.depaul.edu> wrote:
> > > Make sure Field(...,default=None, update=None)
>
> > > On Jan 14, 9:47 am, Alexandre Andrade <alexandrema...@gmail.com>
> > > wrote:
>
> > > > db.order_detail.total.compute=lambda r: r['qtd']*r['price']
>
> > > > don't work on updates
>
> > > > 2010/1/14 mdipierro <mdipie...@cs.depaul.edu>
>
> > > > > 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 <alexandrema...@gmail.com>
> > > > > 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 web...@googlegroups.com.
> > > > > To unsubscribe from this group, send email to
> > > > > web2py+unsubscr...@googlegroups.com<web2py%2bunsubscr...@googlegroups.com>
> > <web2py%2bunsubscr...@googlegroups.com<web2py%252bunsubscr...@googlegroups.com>
>
> > > > > .
> > > > > 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 web...@googlegroups.com.
> > To unsubscribe from this group, send email to
> > web2py+unsubscr...@googlegroups.com<web2py%2bunsubscr...@googlegroups.com>
> > .
> > 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 web...@googlegroups.com.
To unsubscribe from this group, send email to 
web2py+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/web2py?hl=en.


Reply via email to