Frappe ,Erpnext V15
custom Doctype named : Proposal
when add new proposal i have 2 fields percentage and donor
if the percentage value >0 and <100 then
a button named moreprop displayed
when that button clicked it must duplicate both fields percentage and donor ?
i tried these:
moreprop: function(frm) {
// Duplicate the donor and percentage fields
var donor = frm.doc.donor;
var percentage = frm.doc.percentage;
var newRow = frm.add_child('proposals_donor_section');
frappe.model.set_value(newRow.doctype, newRow.name, 'donor', donor);
frappe.model.set_value(newRow.doctype, newRow.name, 'percentage', percentage);
frm.refresh_field('proposals_donor_section');
},
nextprog: function(frm) {
// Check if all required fields are filled
var requiredFields = ['donor', 'percentage'];
var isFieldsFilled = requiredFields.every(function(field) {
return frm.doc[field] != null; // Check if the value is not null or undefined
});
if (isFieldsFilled) {
// Show the targeted_programs_and_their_percentage_section field if all required fields are filled
frm.set_df_property('targeted_programs_and_their_percentage_section', 'hidden', 0);
frm.refresh_field('targeted_programs_and_their_percentage_section');
} else {
frappe.throw('Please fill all the required fields.');
}
}
});
then :
moreprop: function(frm) {
frappe.run_serially([
function() {
// Duplicate the donor and percentage fields
var donor = frm.doc.donor;
var percentage = frm.doc.percentage;
// Check if donor and percentage fields have values
if (donor && percentage) {
// Create a new row for each donor and percentage value
donor.forEach(function(donorValue, index) {
var newRow = frm.add_child('proposals_donor_section');
frappe.model.set_value(newRow.doctype, newRow.name, 'donor', donorValue);
frappe.model.set_value(newRow.doctype, newRow.name, 'percentage', percentage[index]);
});
frm.refresh_field('proposals_donor_section');
// Clear the donor and percentage fields after duplication
frm.set_value('donor', []);
frm.set_value('percentage', []);
// Reset the moreprop button visibility
frm.set_df_property('moreprop', 'hidden', 1);
frm.refresh_field('moreprop');
} else {
frappe.throw('Please fill in the donor and percentage fields.');
}
}
]);
},
then
moreprop: function(frm) {
frappe.run_serially([
function() {
// Duplicate the donor and percentage fields
var donor = frm.doc.donor;
var percentage = frm.doc.percentage;
frappe.throw('first msg');
// Check if donor and percentage fields have values
if (donor.length > 0 && percentage.length > 0) {
frappe.throw('2nd msg');
// Create a new row for each donor and percentage value
donor.forEach(function(donorValue, index) {
var newRow = frm.add_child('proposals_donor_section');
frappe.model.set_value(newRow.doctype, newRow.name, 'donor', donorValue);
frappe.model.set_value(newRow.doctype, newRow.name, 'percentage', percentage[index]);
});
frm.refresh_field('proposals_donor_section');
// Clear the donor and percentage fields after duplication
frm.set_value('donor', []);
frm.set_value('percentage', []);
// Reset the moreprop button visibility
frm.set_df_property('moreprop', 'hidden', 1);
frm.refresh_field('moreprop');
} else {
frappe.throw('Please fill in the donor and percentage fields.');
}
}
]);
},
it display first msg but did not duplicate the fields !!!
any help thank you