ERPNext Conference 2019* ERPNext.com Blog

jQuery code broken on frappe.ui.Dialog on v11


#1

After I upgraded on version 11, all jQuery code on frappe.ui.Dialog is broken.

Are there any changes? It used to work very well on v10, v9, v8.

EDIT: I need to setTimeout to 200ms or above to make it work.


#2

Can you show the code that broke?


#3

@igrekus This is the original code

let alter_dic = {};
 
let dialog = new frappe.ui.Dialog({
    title: __('Alternative Items'),
    fields: [
    {
        fieldtype: 'HTML',
        fieldname: 'alt_item_name',
        label: __(''),
        reqd: false,
        description: __(""),
        options: rendered_template // HTML code
    },
    {
        fieldtype: 'Column Break',
        fieldname: 'c_break'
    },
    {
        fieldtype: 'HTML',
        fieldname: 'competitor_prices'
    },
    {
        fieldtype: 'HTML',
        fieldname: 'supplier_prices'
    }
    ],
    primary_action_label: __("Ok"),
    primary_action: function () {
            // console.log('test')
            $.each(doc.items, function (i, d) {
 
                if (alter_dic[d.item_code]) {
 
                    if (d.same_as_item_code_above) {
 
                        d.same_as_item_code_above = 0;
                    }
 
                    let original_item = d.item_code;
                    let alter_item = alter_dic[d.item_code];
                    d.item_code = alter_item["item_code"];
                    d.item_name = alter_item["item_name"];
                    d.manufacturer_pn = alter_item["manufacturer_pn"];
                    d.description = alter_item["description"];
                    d.stock_uom = alter_item["stock_uom"];
                    d.sales_item_name = d.item_code;
 
                    if (alter_dic[original_item]["qty"] < d.qty) {
                        d.actual_qty = alter_item["qty"]
                    }
 
                    // d.rate = alter_item['rate'];
                    d.price_list_rate = alter_item['rate'];
 
                    frm.script_manager.trigger("qty", d.doctype, d.name);
                    frm.script_manager.trigger("item_code", d.doctype, d.name);
                    frm.script_manager.trigger("price_list_rate", d.doctype, d.name);
                    frm.script_manager.trigger("rate", d.doctype, d.name);
                    frm.script_manager.trigger("warehouse", d.doctype, d.name);
                }
            });
 
            dialog.hide();
            refresh_field('items');
            // cur_frm.save();
 
        }
    });
 
dialog.show();
dialog.$wrapper.find('.modal-dialog').css("width", "70%");
dialog.$wrapper.find('.modal-dialog').css("height", "70%");
 
// I need to add the code below in setTimeout
$("input[name='sp']").change(function () {
 
    alter_dic[$(this).attr('id')] = {
        "item_code": $(this).closest('td').attr("item"),
        "qty": $(this).closest('td').attr("qty"),
        "item_name": $(this).closest('td').attr("item_name"),
        "manufacturer_pn": $(this).closest('td').attr("manufacturer_pn"),
        "description": $(this).closest('td').attr("description"),
        "warehouse": $(this).closest('td').attr("warehouse"),
        "stock_uom": $(this).closest('td').attr("stock_uom"),
        "rate": $(this).closest('td').attr("rate"),
        "price_list_rate": $(this).closest('td').attr("price_list_rate")
    };
 
    console.log(alter_dic)
});

or https://pastebin.com/HJiCwaWw