surveyjs / survey-creator

Scalable open-source survey software to generate dynamic JSON-driven forms within your JavaScript application. The form builder features a drag-and-drop UI, CSS Theme Editor, and GUI for conditional logic and form branching.
https://surveyjs.io/open-source
Other
862 stars 363 forks source link

`onOpenFileChooser` is not raised from the Property Grid #4687

Closed SamMousa closed 8 months ago

SamMousa commented 9 months ago

Are you requesting a feature, reporting a bug or ask a question?

Bug

What is the current behavior?

The file chooser event is not fired from the property grid, for example for Survey Logo or Image Picker choices image

What is the expected behavior?

It should fire for all file inputs from the property grid, the same as it does for editor decorators (not sure if thats the right term): image

How would you reproduce the current behavior (if this is a bug)?

  1. Navigate here: https://codepen.io/sammousa/pen/mdazope
  2. Click the icon next to Survey Title, confirm you get a javascript alert.
  3. Go into the property grid, Logo in Survey Title
  4. Click the icon next to the logo input
  5. See that the javascript alert is not triggered.

Provide the test code and the tested page URL (if applicable)

Tested page URL: https://codepen.io/sammousa/pen/mdazope

JaneSjs commented 9 months ago

Hello @SamMousa, Thank you for reporting this issue. I confirmed that the creator.onOpenFileChooser event is not fired when a user clicks the file upload button via a property grid. I'll forward this issue to our developers. Meanwhile, please let me clarify your usage scenario. Do you use this event to override the standard file chooser?

SamMousa commented 9 months ago

Yes I do. We use a file picker / media manager to allow the user to pick already uploaded files as well as upload new ones.

SamMousa commented 9 months ago

Btw, the docs for this onOpenFileChooser suggests it's mandatory to call the callback. Are we allowed to not call it in case the user canceled the action? image

JaneSjs commented 8 months ago

Hello @SamMousa, Thank you for the update. I forwarded this issue to our developers for further research.

Regarding your additional question: without a callback function, files won't be processed or handled in any way, and the creator.onUploadFile function won't be executed. However, if a user cancells the file upload action, you can return from a function by calling the return;, like it's done in our source code: https://github.com/surveyjs/survey-creator/blob/63c3a46384d53ee8044763adec7ab551313a3577/packages/survey-creator-core/src/creator-base.ts#L2777C63-L2777C69. As you can see, if no files are selected (e.g., if the user cancels the file dialog), the code simply returns and does nothing further. In this specific case, not providing a callback function won't cause any unhandled results or actions because the code handles the scenario where no files are chosen. You can implement a similar routine to handle file uploads in your code.

Please le tme know if you have any further questions.

SamMousa commented 8 months ago

Hi @JaneSjs, I think I haven't explained my additional question correctly. Even though from your answer I can extract what I need to know...

I was talking about the fact that the documentation (see my image above) says:

options.callback - need to be called after files have been chosen

The docs don't tell us about what to do if the user canceled the action. From your answer I conclude that I simply do not call the callback.

You also mention to just "return from the function", but this suggests a lack of understanding of asynchronous programming. My function always instantly returns... I launch the popup for the file picker, and give it the callback. Then I return from the function without waiting for the dialog to appear, or the user taking any action.

Anyway, thanks for your time, I look forward to the bugfix!