I also have this kind of problem and this is my query.
frappe.ui.form.on(‘Material Request’, {
onload: function(frm) {
// Fetch and set parent item groups in custom_item_groups field
frappe.call({
method: “frappe.client.get_list”,
args: {
doctype: “Item Group”,
filters: {
‘is_group’: 1,
‘parent_item_group’: null // Fetch top-level item groups
},
fields: [“name”]
},
callback: function(r) {
if (r.message) {
let parent_item_groups = r.message.map(item => item.name);
console.log(“Parent item groups fetched:”, parent_item_groups);
frm.set_df_property(‘custom_item_groups’, ‘options’, parent_item_groups.join(‘\n’));
frm.refresh_field(‘custom_item_groups’);
}
}
});
},
custom_item_groups: function(frm) {
console.log(“Custom item group selected:”, frm.doc.custom_item_groups);
apply_item_code_filter(frm);
}
});
function apply_item_code_filter(frm) {
let item_group_filter = frm.doc.custom_item_groups;
console.log(“Applying item code filter based on custom item group:”, item_group_filter);
if (item_group_filter) {
// Fetch and filter items based on the selected parent item group
frappe.call({
method: "frappe.client.get_list",
args: {
doctype: "Item",
filters: {
'item_group': item_group_filter
},
fields: ["item_code", "item_name"]
},
callback: function(r) {
if (r.message) {
let filtered_items = r.message;
console.log("Filtered items fetched:", filtered_items);
// Clear the existing items table
frm.clear_table('items');
// Add the filtered items to the items table
filtered_items.forEach(item => {
let child = frm.add_child('items');
child.item_code = item.item_code;
child.item_name = item.item_name;
});
frm.refresh_field('items');
} else {
// If no items found, clear the items table
frm.clear_table('items');
frm.refresh_field('items');
}
}
});
} else {
// If no custom item group is selected, clear the items table
frm.clear_table('items');
frm.refresh_field('items');
}
}
I have a field called Item Group all item groups should be displayed in this field. But when I click food for example. The items in the table did not filter. Can you help me with this because I’m stuck in here. Thanks
I need a search functionality for selecting a data type. When we enter some characters into the search field, it should call an API and fetch data based on the characters entered. We should then be able to select the data retrieved from the API.
Hi, this is not my problem. I know how to specify the link type in DOCTYPE. My problem is that when a user type something, a dropdown should appear based on that input. The values in the dropdown should be fetched dynamically from the code base on a field event.
So you don’t want to filter the values of a link field, instead you want something similar to a dynamic link where you give an input and the drop-down gets generated dynamically based on the input?
I think if you can increase the limit of Link field result to maximum as below in system settings, you may start getting more similar results based on your search criteria.