I have a web form, it has a link field named branch. so when users clicks on the field 9 branches are being shown as option. I want to show only 7 branches. how can i do it?
getting error ‘frappe.web_form.on()’ is not a function. for below code
frappe.web_form.on('branch', (field, value) => {
console.log("Setting query for branch 2");
const allowedBranches = [
"branch1",
"branch2",
"branch3"
];
var branchField = frappe.web_form.get_field('branch');
if (branchField) {
console.log("branch field")
// Prepare options in the format { label: '...', value: '...' }
var options = allowedBranches.map(branch => ({
label: branch,
value: branch
}));
console.log("adding branch field filtered options")
// Assign the options to the field and refresh
branchField._data = options;
branchField.refresh();
console.log("Branch options filtered:", options);
} else {
console.error("Branch field not found!");
}
});
also tried this code
frappe.web_form.after_load = ()=>{
console.log("Web Form Loaded 2");
// Allowed branches
const allowedBranches = [
"branch1",
"branch2",
"branch3"
];
// Get branch field object
var branchField = frappe.web_form.field_group.get_field('branch');
if (branchField) {
// Prepare options in the format { label: '...', value: '...' }
var options = allowedBranches.map(branch => ({
label: branch,
value: branch
}));
console.log("adding branch field filtered options")
// Assign the options to the field and refresh
branchField._data = options;
branchField.refresh();
console.log("Branch options filtered:", options);
} else {
console.error("Branch field not found!");
}
};
one doubt i have is that all the code should be inside frappe.ready() or not?
frappe.ready(function() {}