Jam.py documentation

on_field_changed

on_field_changed(field, lookup_item)

domain: client

language: javascript

class Item class

Description

Write an on_field_changed event handler to respond to any changes in the field’s data.

The field parameter is the field whose data has been changed. To get the item that owns the field, use the owner attribute of the field.

The lookup_item parameter is not undefined when the field is a lookup field and a change has occured when a user selected a record from a lookup item dataset.

Example

function on_field_changed(field, lookup_item) {
    var item = field.owner;
    if (field.field_name === 'quantity' || field.field_name === 'unitprice') {
        item.owner.calc_total(item);
    }
    else if (field.field_name === 'track' && lookup_item) {
        item.quantity.value = 1;
        item.unitprice.value = lookup_item.unitprice.value;
    }
}