TimOetting / kirby-builder

A site builder extension for Kirby CMS
398 stars 51 forks source link

File selection in textareas (via toolbar) #110

Closed nilshoerrmann closed 2 years ago

nilshoerrmann commented 5 years ago

We are using a textarea inside the builder and would like to select images via the toolbar, see https://getkirby.com/docs/reference/panel/fields/textarea#file-upload-and-select. This results in the following error:

Bildschirmfoto am 2019-04-05 um 13 16 07

Here is a reduced version of our blueprint:

interview:
  type: builder
  label: Interview
  fieldsets:
    questionset:
      label: Frage
      fields:
        question:
          type: textarea
          label: Frage
          files: page.images

My guess is that the context page.images is wrong given the nested structure: How do we have to define the files options to enable image selection?

andrewcio commented 5 years ago

Noticed this as well. On 3.2.0. However, file uploading seems to be working fine.

nwong212 commented 5 years ago
Screen Shot 2019-09-29 at 7 26 21 PM

Same Issue, File upload seems fine, but file selection is not working...

MaxAIPlayground commented 5 years ago

Same issue here.

tideg commented 5 years ago

... and here on 3.3.0

alancwoo commented 4 years ago

Ah, I came to create the same issue and will write it out here so it actually appears in search:

Invalid file model type: kirby-builder/pages ...

I'm on Kirby 3.3.0

alancwoo commented 4 years ago

I'm trying to look into this a bit further as it's really blocking me from shipping a project using builder.

Looking at the network requests, the builder textarea filepicker makes a call like so: https://DOMAIN/api/kirby-builder/pages/SLUG/fields/FIELD_NAME/files?page=0 which fails with the Invalid file model type 400 error.

A default textarea makes the call like so: https://DOMAIN/api/pages/SLUG/fields/FIELD_NAME/files?page=0 which of course works.

Looking at the codebase, it looks like the url is set here https://github.com/TimOetting/kirby-builder/blob/88c6d13ba96cd3a68fb57c6567fb69fb61201560/src/components/BuilderBlock.vue#L291 but I'm at a bit of a wall at this point.

The only solution (clearly a terrible one) I've found is hard-coding the path to a known working endpoint:

field: `kirby-builder/${modelEndpoint}/fields/${this.blockPath}+${fieldSet.fields[fieldName].name}`,

to

field: `kirby-builder/${modelEndpoint}/fields/EXISTING_DEFAULT_TEXTAREA_NAME`,

@TimOetting I am sorry to bug you but any tips would be greatly appreciated as I am completely stuck here.

alancwoo commented 4 years ago

Ok, this is my absolutely terrible solution for now, unless @TimOetting or someone else can let me know the right way to fix this bug.

In the root of the kirby-builder folder, I define a .env.local file:

DEFAULT_TEXTAREA=text
BUILDER_TEXTAREAS=some,builder,textareas

Where DEFAULT_TEXTAREA is the name of a default textarea field that exists in the blueprint, and BUILDER_TEXTAREAS are the names of builder textarea fields.

Then changed https://github.com/TimOetting/kirby-builder/blob/88c6d13ba96cd3a68fb57c6567fb69fb61201560/src/components/BuilderBlock.vue#L290 to:

if (process.env.BUILDER_TEXTAREAS.split(',').indexOf(fieldName) >= 0) {
    fieldSet.fields[fieldName].endpoints = {
    field: `${modelEndpoint}/fields/${process.env.DEFAULT_TEXTAREA}`,
    model: modelEndpoint,
    section: this.endpoints.section
    };
} else {
    fieldSet.fields[fieldName].endpoints = {
    field: `kirby-builder/${modelEndpoint}/fields/${this.blockPath}+${fieldSet.fields[fieldName].name}`,
    model: modelEndpoint,
    section: this.endpoints.section
    };
}

Then npm run build for the production build.

It's odd that file fields work without issue.

mourique commented 4 years ago

thanks @alancwoo that actually worked! i can use this as a workaround. one thing that messed me up though: your first line says: if (process.env.BUILDER_TEXTAREAS.split(',').indexOf(fieldName) >= 0) { i needed to change it to double brackets as in if (process.env.BUILDER_TEXTAREAS.split(",").indexOf(fieldName) >= 0) { then, after npm run build it worked. sadly this hack needs an otherwise useless simple textarea to be present and needs to be updated once the blueprint is changed.

btw, there is a response regarding this topic by @TimOetting in the kirbyforum: https://forum.getkirby.com/t/error-message-when-selecting-file-in-textarea/13568/5

seems like the problem could be in kirby-core? but i am not really sure about that.

TimOetting commented 2 years ago

Closing this issue because this plugin will no longer be maintained, as its main functionality can be replaced by Kirby's built-in Blocks Field and Layout Field.