Hi everyone,
I’m working on a Frappe project where I need to automatically set default filters when a popup dialog opens. Specifically, I want to set the “Item Code (Batch No Details)” as the default filter field and set its value to a specified item code.
I have tried the following code to add and set the filter automatically:
javascript
Copy code
frappe.after_ajax(() => {
setTimeout(() => {
// Click to add the filter
$(“.add-filter”).click();
// Set the filter field (for example, "Item Code (Batch No Details)")
let fieldElement = $("[aria-owns='awesomplete_list_34']");
fieldElement.val("Item Code (Batch No Details)").trigger("input");
let options = [item_code];
let htmlContent = '';
options.forEach(function (option) {
htmlContent += `<li>${option}</li>`;
});
// Set the HTML content in the element with the specified ID
let listElement = $("[id='awesomplete_list_35']");
if (listElement.length) {
listElement.html(htmlContent);
}
let valueElement = $("[aria-owns='awesomplete_list_35']");
valueElement.val(item_code).trigger("input");
valueElement.trigger("change");
}, 500); // Initial timeout to allow dialog to render
});
While this code successfully adds the filter and sets the field to “Item Code (Batch No Details)”, the value field does not change to reflect the item list as expected. Manually selecting “Item Code” from the filter dropdown updates the value field to show the item list, but I need this to happen automatically.
Attached are screenshots for reference:
Can anyone provide guidance on how to ensure the value field updates correctly to show the item list when the filter is set programmatically?
Thanks in advance!