uploadcare / file-uploader

Stack-agnostic library for uploading, processing, and editing images on-the-fly
https://uploadcare.com/docs/file-uploader/
MIT License
88 stars 14 forks source link

Allow <input> names without [] suffix for singular file uploaders #601

Closed evgkirov closed 9 months ago

evgkirov commented 9 months ago

Is your feature request related to a problem? Please describe.

When updating Blocks in pyuploadcare from version 0.30.7 to 0.32.1, I encountered an issue with singular file uploaders. Previously, I used <lr-data-output> to create a singular <input> with name="logo", which aligns with Django's expectations.

<lr-data-output
        ctx-name="logo"
        style="position: absolute;"
        use-input
        input-required
></lr-data-output>

However, with Blocks v0.32.x transitioning to <lr-form-input>, the <input> names now include a [] suffix, as described in the documentation. While I understand the benefits of this approach, it doesn't align with Django's expectation of logo without the [] suffix for singular uploads.

Describe the solution you'd like

I propose adding a new setting within <lr-config> that allows disabling the array-style input names for singular uploads. This would provide users with more control over the naming convention, allowing compatibility with frameworks like Django.

nd0ut commented 9 months ago

Yeah, it sounds like a bug. When "multiple" is disabled, we shouldn't append [] to the input name. I'll fix it tomorrow.

nd0ut commented 9 months ago

Just to clarify, under "singular uploads" you mean exactly when "multiple" is false, right?

evgkirov commented 9 months ago

multiple is false or not set.

nd0ut commented 9 months ago

multiple is false or not set.

but multiple is enabled by default

evgkirov commented 9 months ago

My bad. I shall re-check. 

evgkirov commented 9 months ago

It does add [] even though multiple="false" is set.

Test case test.html: ```html








      
``` Output: ```json [ [ "fname", "John" ], [ "my-uploader[]", "https://ucarecdn.com/57eb7632-5085-4a1d-9f6b-e092d1637d76/" ] ] ```
nd0ut commented 9 months ago

Fixed in https://github.com/uploadcare/blocks/releases/tag/v0.32.2, check it please