Couldn't hide(close) multi select dialog

Hello every body,
I have created custom dialog in purchase receipt to get items from material request
dialog works fine but not closed when I click "get Items "
I tried “d.hide()” it returns

Uncaught TypeError: d.hide() is not a function

so how to make it close properly?
my script:

   function show_material_request_dialoug(frm,cdt,cdn) {
      
    	let d =new frappe.ui.form.MultiSelectDialog({
                  doctype: "Material Request",
                  target: cur_frm,
                
                 primary_action_label: __("Get Items"),
                  setters: {
                      company:frm.doc.company,
                      // supplier:frm.doc.supplier
                  },
                  date_field: "transaction_date",
                  get_query() {
                       return {
                        filters: { docstatus: ['!=', 2] }
                  }},
                  action(selections) {
                      // console.log(selections);
                     
                      cur_frm.clear_table('items');
                  for(var x in selections){
                      
                  frappe.call({
                    method: "frappe.client.get",
                    args: {
                        doctype: "Material Request",
                        fields: ["items"],
                        filters: { 'name':  selections[x] },
                    },
                        callback: function(res){
                          
                            res.message.items.forEach(function (item) {
                      
                       var child = cur_frm.add_child('items');
                       frappe.model.set_value(child.doctype, child.name, 'item_code', item.item_code);
                       frappe.model.set_value(child.doctype, child.name, 'qty', item.qty);
                       frm.refresh_field('items'); 
                       
                   
                   });
                  //         
                }})
                       
           
              }
               d.hide();      
                  }  
    	    
    	});
       
           }

Error:

I am facing the same issue…

    frm.addMultipleAnalysis = () => {
        let d = new frappe.ui.form.MultiSelectDialog({
            doctype: "Analysis",
            target: "Sample",
            setters: {
            },
            date_field: "transaction_date",
            get_query() {
                return {
                    filters: {docstatus: ['!=', 2] }
                }
            },
            action(selections) {
                let leng = selections.length;
                for (let i = 0; i < leng; i++) {
                    let curName = selections[i];
                    frm.getListNames("Analysis", curName);
                  };
            }
        });
    };

I am unable to hide the dialogbox. I have tried d.hide() but it does not work ://

@Zeinab_Mohammed You can use jquery to hide the modal
in action(selection) add this $(“.modal”).modal(“hide”); to bottom

2 Likes

Where should I add this in the above code?

In the Action button

1 Like

You mean after the following for loop?

yes, he means that but outside the for loop braces


I have added the code in the above line number 45 but now the page is not loading because of the following syntax error:

use this one:

cur_dialog.hide();

1 Like

Use d.dialog.hide();

Ex:
let d = new frappe.ui.form.MultiSelectDialog ({

action(selections, args) {
d.dialog.hide();
‘your_actions’
}
});

2 Likes


why i cant access cur_dialog ?

cur_dialog.hide();
it works for me on line# 151

The error occurs because d.hide() is not recognized as a function for closing the dialog in your current code. Instead, try using d.dialog.hide() to close the dialog properly. Here’s the updated part of your script:

function show_material_request_dialoug(frm, cdt, cdn) {
let d = new frappe.ui.form.MultiSelectDialog({
doctype: “Material Request”,
target: cur_frm,
primary_action_label: __(“Get Items”),
setters: {
company: frm.doc.company,
},
date_field: “transaction_date”,
get_query() {
return {
filters: { docstatus: [‘!=’, 2] }
};
},
action(selections) {
cur_frm.clear_table(‘items’);
selections.forEach(selection => {
frappe.call({
method: “frappe.client.get”,
args: {
doctype: “Material Request”,
fields: [“items”],
filters: { ‘name’: selection },
},
callback: function(res) {
res.message.items.forEach(item => {
let child = cur_frm.add_child(‘items’);
frappe.model.set_value(child.doctype, child.name, ‘item_code’, item.item_code);
frappe.model.set_value(child.doctype, child.name, ‘qty’, item.qty);
});
frm.refresh_field(‘items’);
}
});
});
d.dialog.hide(); // Updated to use d.dialog.hide()
}
});
}