Custom script to instantly calculate

Hello,

I am trying to calculate a cubic meter according to my custom fields length, width and height automatically and most important instantly.

I managed to do it with the examples of the manual but only after saving.

here is my script:

// CBM field read-only
cur_frm.cscript.custom_onload = function(doc) {
    cur_frm.set_df_property("cbm", "read_only", 1);
}

// Calculate CBM
cur_frm.cscript.custom_refresh = function(doc) {
    cbm = doc.length * doc.width * doc.height;
    cur_frm.set_value("cbm", cbm);
}

How can I make it instantly updated?

Is there a documentation for scripts? Like what properties can be used for set_df_property appart from read-only or what events are available for cur_frm? It would really help

Thank you

You can all this function on trigger of length, width or height

frappe.ui.form.on("your doctype", {
  "length": function(frm) { 
    frm.cscript.custom_refresh();
  }
});

Thanks, but I’m not sure I get it… How do I trigger this with your code?

This binds it to the change event. What do you want to trigger?

I want my script to be instantly executed when changing any of the 3 custom fields (length, width or height) to instantly see the result in the cbm field.

cur_frm.cscript.custom_refresh = function(doc) {
    cbm = doc.length * doc.width * doc.height;
    cur_frm.set_value("cbm", cbm);
}

For now it’s only done when saving the doc.

You need to bind the event to all three fields (like I explained in the example above)