frappe-better-attach-control icon indicating copy to clipboard operation
frappe-better-attach-control copied to clipboard

[BUG]: Incorrect path for API request

Open qbadev opened this issue 1 year ago • 7 comments

When JS frontend tries to retrieve options data for Attach Field, it goes to not existing route. When inspecting network request in dev console, it show api/method/frappe_better_attach_control.api.get_options, but there is no api controller selected. It should be api/method/frappe_better_attach_control.api.field.get_options.

I think, starting in https://github.com/kid1194/frappe-better-attach-control/blob/04cb21b656595cd80f70d72e9779ca36fb506324/frappe_better_attach_control/public/js/controls/attach.js#L305-L306 there should by:

request(
  'field.get_options',

qbadev avatar Feb 20 '24 12:02 qbadev

@qbadev Hey bro..

Sorry for the late reply, and thank you for reporting this bug..

As you can see below, the field file is fully imported so calling frappe_better_attach_control.api.get_options instead of frappe_better_attach_control.api.field.get_options should be fine but I think that it doesn't work like this in frontend..

https://github.com/kid1194/frappe-better-attach-control/blob/04cb21b656595cd80f70d72e9779ca36fb506324/frappe_better_attach_control/api/init.py#L8

Anyway, thanks to you I will make this change in the frontend js files..

Best regards..

kid1194 avatar Feb 22 '24 22:02 kid1194

Path in frontend must be strictly valid against frappe api pattern and rules, I guess. I tested it out already: path field.get_options works fine.

qbadev avatar Feb 22 '24 22:02 qbadev

There might be other places that require correction in frontend. I am not sure, but I recall other errors in dev console in browser indicating similar issue.

qbadev avatar Feb 22 '24 22:02 qbadev

@qbadev Hey bro..

Can you please post a screenshot for all the errors you see in console or anywhere else?

Your help is much appreciated 😁

Best regards..

kid1194 avatar Feb 23 '24 23:02 kid1194

When clicking Attach Image control button in the form, nothing happens visualy, but the error shows up in console log.

attach.js:125 Uncaught TypeError: Cannot read properties of undefined (reading 'allowed_file_types')
    at attach.js:125:33
    at frappe.ui.form.ControlAttachImage.on_attach_doc_image (attach.js:135:13)
    at frappe.ui.form.ControlAttachImage.on_attach_click (attach.js:110:37)
    at HTMLButtonElement.click (attach.js:9:9)
    at HTMLButtonElement.dispatch (jquery.js:5135:27)
    at Rt.handle (jquery.js:4939:28)
(anonymous) @ attach.js:125
on_attach_doc_image @ attach.js:135
on_attach_click @ attach.js:110
click @ attach.js:9
dispatch @ jquery.js:5135
Rt.handle @ jquery.js:4939

It is a result of not receiving proper data from ajax request.

qbadev avatar Feb 26 '24 12:02 qbadev

I also noticed that Your api field file algorithm does not check tabCustom Field table for possible values. Another issue is that JS FE script tries to check field named image hardcoded, while one can have multiple fields in one form with totally different names.

qbadev avatar Feb 26 '24 13:02 qbadev

@qbadev Hey bro..

Sorry for the late reply..

Regarding the console error, I don't know exactly why its happening so I have added a simple check in order to avoid the error..

I also noticed that Your api field file algorithm does not check tabCustom Field table for possible values.

You have noticed a great mistake of mine 😅 I have added the Custom Field query..

Another issue is that JS FE script tries to check field named image hardcoded, while one can have multiple fields in one form with totally different names.

I can't really find the exact code that you are referring to so can you please help me by pointing it out..

I have created this long time ago and when I look at the codes now I feel that it wasn't me who wrote them 😅

Maybe I will recreate this plugin and make it much more better..

Thanks a lot bro for your help. I'm really grateful..

Best regards..

kid1194 avatar Mar 02 '24 00:03 kid1194