Set value in Child form when make change in same form

Hi I Need help with two things.

  1. How can I change a value in the child form(child), when I change a value in the same child form?
  2. Also change the value in the parent form, when i change the value in the child form?

when i use
frappe.ui.form.on(“Child Doctype”, “field1”, function(frm,cdt,cdn) {

});
inside parent_doctype.js
the function is working but how can i set value to field2 in childdoctye

@ninjas005

frappe.model.set_value("DocType", "DocName", "fieldname", "value")

Yup , i know :smiley:

But I need to check if field3>10
then set value
but when i use if(frm.field3>10)
frm.field3 is undefined

frm refers to parent form

Ans : 1
frappe.ui.form.on(“child table name” , “field_name”, function(frm, cdt, cdn) {

        method : 1 
               ---------------------------------------
              var item = frappe.get_doc(cdt, cdn);
              item.fied = "Value to be set"


       method : 2  
                
             locals[cdt][cdn]['fied']  = "Value to be set"

}

Ans : 2

cur_frm.set_value(“fied”, ‘Value to be set’);

1 Like

@ninjas005 use:

var parent = frm.doc,
     child = locals[cdt][cdn];
1 Like

Hi @max_morais_dmm , @Nishant_Jariwala

Thanks for your help.
The first part was completed.
My second question was ,
“change the value in the parent form, when i change the value in the child form”
I actually want to do it when the form (modal) for the child form closes.(ie, when all fields in the child form has given values and new row is added to child table).

Please tell me how I can trigger it?

I’ve tried

frappe.ui.form.on(“ParentDoctype”, “child_table_field_name”, function(frm,cdt,cdn) {

});

But not working. Please help me with this too.

Currently dont have a event for this, do you need choice a fiel that after changed change the parent too

1 Like

right @max_morais_dmm
@ninjas005 you need to choice a field after that change the parent too

1 Like

Hi ,
I did it when in form refresh.
When a new row is added , the form is refreshed :smile:

thank you

But when the child table row is modified, refresh is not triggered.

Hi @max_morais_dmm, @Nishant_Jariwala

Is there any way to know when a child tale row is removed?

@ninjas005 have 2 events:

“before_” + fieldname + “_remove”
fieldname + “_remove”

Both listed upon the parent

@max_morais_dmm
please give an example event function header line
i didn’t get it

@ninjas005

frappe.ui.form.on("Sales Invoice", "before_item_remove", function(doc, cdt, cdn){});
1 Like

Thanks @max_morais_dmm
Lemme try

In the server side , i get the self.item (item - child table field name) as [] or [,].
You know why?
How can i get the value of item as a list or dict?

@ninjas005

first tip: dont change the context of the thread!
second tip: if you have a long list of queries, enumerate it in a single thred with all points, or, start discussing on gitter chat gitter.im/frappe/erpnext

Hi @max_morais_dmm

Am sorry for that question…I will try to post related to the thread.

what do you mean by upon parent?
Should I use the event in the parent form?

is that so , following code didn’t work for me

frappe.ui.form.on(“Summative Assesment”, “students_list_remove”, function(doc, cdt, cdn)
{
//
});

But it did

frappe.ui.form.on(“Students List”, “students_list_remove”, function(doc, cdt, cdn)
{
//
});

@ninjas005, these events are customizes with a fieldname, so the name of the doctype, passed first is the name of the doctype that contains the fieldname, in this case the parent.

Maybe you have a typo in the fieldname, of a unattented extra space

hi,
please tell me how can i cancel the deletion of the row within the above function?