mplodowski / formbuilder-plugin-public

https://octobercms.com/plugin/renatio-formbuilder
https://octobercms.com/plugin/renatio-formbuilder
2 stars 0 forks source link

FileUploader onRun Does Not Run, Does Not Inject Assets #37

Closed sqwk closed 11 months ago

sqwk commented 1 year ago

When using a file uploader field, the needed JS and CSS assets do not get injected. (The onRun method of the File Uploader component, where addJS() and addCSS() are called, is never executed.)

October v3.4.15

Plugin v3.1.3

mplodowski commented 1 year ago

Hmm it is called on my test project. I checked form inside CMS Page, Static Page (component snippet).

Did you install responsiv/uploader-plugin using composer?

Please explain how do you use form and where do you put it.

sqwk commented 1 year ago

I installed the uploader plugin through the October CMS project / the backend.

The form is embedded into a static page (variable, not the content field) via a snippet: <figure data-ajax="true" data-component="Renatio\FormBuilder\Components\RenderForm" data-property-formcode="some-form" data-snippet="renderForm">&nbsp;</figure>

mplodowski commented 1 year ago

I don't understand the part (variable, not the content field). Can you elaborate on this?

I have a static page and I clicked on the Snippets menu on the top bar then choose Render Form Component. I clicked on the snippet and choosed the form.

The second form I added using richeditor Insert Snippet button.

The result on the static page source code:

<figure data-ajax="true" data-component="Renatio\FormBuilder\Components\RenderForm" data-property-formcode="default-form" data-snippet="renderForm">&nbsp;</figure>
<figure data-component="Renatio\FormBuilder\Components\RenderForm" data-property-formcode="contact-form-2" data-snippet="renderForm1">&nbsp;</figure>

Both forms work fine (image upload and file upload works). Hmm they even work when I remove this data-ajax="true" attribute, which is weird.

sqwk commented 1 year ago

By variable I mean that the static page does not use the default content field, but a custom repeater. The snippet is inserted in that rich editor, not in the default content field.

layout.htm

[staticPage]
useContent = 0
==
{repeater name="sections" groups="themes/some-theme/meta/generic-repeaters.yaml" tab="Content" prompt="Add a section"}
    {# parser fail if there is noting between open and close tag #}
{/repeater}

generic-repeaters.yaml

text:
    name: Text
    titleFrom: title
    description: Text
    icon: icon-newspaper-o
    fields:
        title:
            label: Title
            type: text
            span: full
        content:
            label: Content
            type: richeditor
            span: full
mplodowski commented 1 year ago

Hi,

I managed to replicate this issue. As I can see it, the onRun methods of formbuilder plugin as well of fileupload plugin are running, but the assets are not injected. Maybe it is too late in the process of serving page. Maybe this is a bug of October, so they can help with this issue.

I tried to solve this by adding missing assets manually with onStart() function. This works, but another problem is the fileupload component is not bound to controller and ajax handler onUpload() is missing when you try to add file using the form. This also can be an issue how October handle this type of snippets.

If you have time please report this to October team, maybe they will figure this out.

sqwk commented 1 year ago

OK, good to know that is not only isolated to my test system. Unfortunately, I am not 100% what to report to the October team. I have tried playing with the code, but haven't really come to any conclusion.

As of now; I believe that it might be best to remove the Uploader dependency entirely, since October's AJAX framework apparently supports uploads in v3. (See https://github.com/responsiv/uploader-plugin/issues/77 and https://docs.octobercms.com/3.x/cms/features/uploads.html) No need for nested components, it removes three JS dependencies and it could potentially be much cleaner.) Happy to open another ticket for this.

mplodowski commented 1 year ago

Yeah I agree, that would be the best way to proceed this. I will try my best to add this feature next week.

mplodowski commented 11 months ago

As discussed I added ajax file uploads in v4.0, so this should be fixed.