In a custom app I have a field with fieldtype button. And I want to add action to it. I want to run a method then return a value to fill a data field and check the checkbox when the button pressed.
To my understanding there are 3 options:
Server script: using the button options I can connect it to a method on doctype_name.py file.
Client script: using doctype_name.js directly add action to the button.
Both: using js to make frappe.call to server method and return the action.
But using #1 I can’t check the box and fill the data field.
Using #2 I can’t run the server method.
Using #3, the frappe.call method path is not recognized because the py file is in the same doctype directory.
Thanks @hashir,
I’m not doing a dialog. My question is related to the field type of Button in a custom doctype.
And it is also not the button on that top page head next to the Save button.
oops, my bad. i understood initially that you need function to have checkbox to select from it.
i’m not an expert and not sure at all, but i think option 3 is the best way to go, why not copy the same function to a different file like util.py and give its path in the js file?
#1 using the server script, I don’t know how to change the display of checked checkbox after setting the value to 1.
#3 using the js to catch the button click and send it to py code via frappe call. But since the doctype_name.py file is in the doctype directory (in app/app/doctype/doctype_name.py) I don’t know how to write the path because frappe doesn’t recognize a py file in doctype directory of a custom app.
Hi @rtdany10,
How to call the method within a class?
If the def is outside the class it can be called (whitelisted or not) using the path, but not if inside a class.
I have a fieldtype button which I process the method directly in py file of the doctype. Not in js.
But since I want to change the hidden/show of other fields, I need to do it in js, right?
Is there a way to change field property directly from py?
As my initial post, there are 3 ways to link method to button. Each has their own limitation (as I know, and I’m not a developer )
So the last post of mine was in related to calling a py method from frappe.call(), where that method is inside a class. So it can return a value to js to change the field property.