Thanks to all!
The necessary code to solve it, is:
on Tg 0.9a9
=== in kid template ===
...
<head>
<script type="text/javascript" rc="/static/javascript/test.js"></script>
</head>
<body onload="ajax_setup()">
${form.display(form_data)}
</body>
=== test.js ===
function ajax_setup(){
connect(document.modificar.field1, 'onchange', sumfields);
connect(document.modificar.field2, 'onchange', sumfields);
}
function sumfields(){
var myform = document.modificar;
var field1val = parseInt(myform.modificar_field1.value) || 0;
var field2val = parseInt(myform.modificar_field2.value) || 0;
myform.suma.value = field1val + field2val;
}
=== in app.cfg ===
...
# List of Widgets to include on every page.
tg.include_widgets = ['turbogears.mochikit']
=== in controllers.py ===
...
class MyCampos(W.WidgetsList):
id = W.HiddenField(validator=v.Int)
field1 = W.TextField(label="fiedl1",validator=v.Int)
field2 = W.TextField(label="field2",validator=v.Int)
suma = W.TextField(label="Suma",validator=v.Int)
class MyForm(W.ListForm):
fields = MyCampos()
name="modificar"
template = "tgtest.templates.editform"
Karl Guertin escribió:
> On 8/31/06, Maram <[EMAIL PROTECTED]> wrote:
>> I newbie in javascript... you have same code... for that...?
>
> I'm going to give you pseudo-javascript because I can't remember the
> TG widget naming conventions and I'm too lazy to look them up. :]
>
> Let's say your form has an id of 'myform' and your fields are named
> 'field1','field2', and 'sum'.
>
> Your javascript file will look something like:
>
> var sumfields = function(){
> var myform = $('myform'); //getElementById('myform')
> var field1val = parseInt(myform.field1.value) || 0; //if parseInt
> fails, set value to 0
> var field2val = parseInt(myform.field2.value) || 0;
> myform.sum.value = field1val + field2val;
> }
>
> //initialize page
> connect(window,'onload', function(){
> var myform = $('myform');
> connect(myform.field1, 'onchange', sumfields);
> connect(myform.field1, 'onchange', sumfields);
> });
>
>
> You can ensure MochiKit is on the page by adding the MochiKit widget
> to the page and if you want a clean way to integrate and reuse your
> js, take a look at JSSource.
>
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"TurboGears" 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/turbogears
-~----------~----~----~----~------~----~------~--~---