hello everyone,
I’m making a page that has 4 link fields but one need to filter it values using the value in the others.
Normally a use set_query function in a doctype and i was searching in ERPNext and found a parameter named filter.
How can i filter the values of link field 2 using the value in link field 1 in a page?
Example Code:
var classroom = frappe.ui.form.make_control({
parent: wrapper.body.find(".classroom"),
df: {
fieldtype: "Link",
options: "ClassRooms",
fieldname: "classroom",
placeholder: "Class Room"
},
only_input: true
});
var teacher = frappe.ui.form.make_control({
parent: wrapper.body.find(".teacher"),
df: {
fieldtype: "Link",
options: "Teachers",
fieldname: "teacher",
placeholder: "Teacher"
},
only_input: true
});
filter all the teacher that has a class in the classroom selected. For example
rmehta
2
In this case you can’t use filter becuase its a static function, you can use get_query to return the filter options though.
Thanks for your answer. Now It’s working. +1
1 Like
Hi @narcisonunez please give us your solution? I need to use get_query for page, but I not sure where I will put it to.
Thanks .
@Khang_Le You can use something like below
frappe.pages["test-page"].on_page_load = function (wrapper) {
frappe.ui.make_app_page({
parent: wrapper,
title: "Test",
single_column: false,
});
frappe.test = new Test(wrapper);
};
class Test {
constructor(wrapper) {
this.data ={}
this.init_fields();
}
init_fields(){
this.project = frappe.ui.form.make_control({
df: {
label: __("Project"),
fieldtype: "Link",
fieldname: "project",
options: "Project",
reqd: 1,
onchange: () => {
this.data.project = this.project.get_value();
},
},
render_input: true,
});
this.task = frappe.ui.form.make_control({
df: {
label: __("Task"),
fieldtype: "Link",
fieldname: "task",
options: "Task",
reqd: 1,
get_query: function () {
const project = frappe.test.project.value;
if (!project) {
frappe.throw(__("Please select Project"));
}
return {
filters: {
project: project,
},
};
},
onchange: () => {
this.data.task = this.task.get_value();
},
});
}
1 Like