The get_values() property of Dialog is not working as expected in secondary_action but works as per expectation in primary_action.
Using JS Dialog API. I have some dummy data and then 2 action buttons. In Primary action function the get_values() function outputs the expected value, but in secondary action function, it’s undefined even though it’s exactly the same.
this.data = [
{
"Kids Size": "18-24", "UnitPrice": "\u20b9 100.00", "BoxPrice": "\u20b9 500.00", "Qty": 0
},
{
"Kids Size": "26-30", "UnitPrice": "\u20b9 110.00", "BoxPrice": "\u20b9 550.00", "Qty": 0
},
{
"Kids Size": "30-36", "UnitPrice": "\u20b9 120.00", "BoxPrice": "\u20b9 100.00", "Qty": 0
}
]
const fields = [{
fieldtype: 'Data',
fieldname: "Kids Size",
in_list_view: 1,
read_only: true,
in_place_edit: false,
disabled: 1,
label: "Kids Size",
}, {
fieldtype: 'Read Only',
fieldname: 'UnitPrice',
read_only: 1,
in_place_edit: false,
in_list_view: 1,
label: __('Price/Unit'),
}, {
fieldtype: 'Read Only',
fieldname: 'BoxPrice',
read_only: 1,
in_place_edit: false,
in_list_view: 1,
label: __('Price/Box'),
},
{
fieldtype: 'Int',
fieldname: "ratio",
default: 1,
read_only: 0,
in_list_view: 1,
label: __('Ratio'),
}, {
fieldtype: 'Int',
fieldname: "qty",
default: 0,
read_only: 0,
in_list_view: 1,
label: __('Qty'),
}];
this.dialog = new frappe.ui.Dialog({
title: __("Select Size"),
fields: [
{
fieldname: "total_qty",
fieldtype: "Int",
label: "Enter Total Qty",
},
{
fieldname: "size_table",
fieldtype: "Table",
label: "Sizes Available",
cannot_add_rows: 1,
in_place_edit: false,
reqd: 1,
data: this.data,
get_data: () => {
return this.data;
},
fields: fields
}
],
primary_action: function () {
console.log(this.get_values())
},
primary_action_label: __('Add to cart'),
secondary_action: function () {
console.log(this.get_values())
},
secondary_action_label: __('Get Qty from Ratio'),
})
The error is coming from the secondary action. But for the same code, in primary action it’s working as expected.