I’m currently working on a project where I’m using Frappe, and I’ve run into a challenge regarding a checkbox field in a child table. I would greatly appreciate your assistance in solving this issue.
In my child table referral_calculation
, I have a field named primary
which is a checkbox. However, I’m trying to achieve a behavior where only one checkbox can be selected at a time. If I select one checkbox, the rest should automatically be unchecked. Essentially, I want to enforce a single selection among the checkboxes in the child table.
You can do this in a custom script. This worked in my end
frappe.ui.form.on('ChildTableDoctype', 'primary', function(frm,cdt,cdn) {
var ch = frm.doc.referral_calculation
var current_row = locals[cdt][cdn]
var current_name = current_row.name
if(current_row.primary == 1) {
for (var i = 0; i < ch.length; i++) {
if(ch[i].name != current_name) {
ch[i].primary = 0
}
else{
ch[i].primary = 1
}
}
frm.refresh_field('referral_calculation');
}
});
1 Like