Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Bug] Upload Field Inside Repeatable Field Not Working Correctly #5657

Open
adrinro opened this issue Sep 12, 2024 · 4 comments
Open

[Bug] Upload Field Inside Repeatable Field Not Working Correctly #5657

adrinro opened this issue Sep 12, 2024 · 4 comments
Assignees

Comments

@adrinro
Copy link

adrinro commented Sep 12, 2024

Description:

The upload field within a repeatable field is not functioning correctly. The issue occurs when attempting to save the form. Despite setting a disk or leaving it unset, the image is not saved in the corresponding storage folder. I have reviewed the view for the repeatable field for any suspicious elements, but nothing seems out of place. When I set the upload field in the subfields, it loads the view crud::fields.upload, but when I try to use dd() to debug, it doesn't seem to reach these dd() statements, making me question which view is actually being loaded.

Code:

<?php
[
    'name' => 'testimonials',
    'label' => 'Testimonios',
    'type' => 'repeatable',
    'fields' => [
        [
            'name' => 'author',
            'label' => 'Autor',
            'type' => 'text',
        ],
        [
            'name' => 'author_image',
            'label' => 'Imagen',
            'type' => 'upload',
            'disk' => 'testimonial',
            'withFiles' => true,
        ],
        [
            'name' => 'quote',
            'label' => 'Cita',
            'type' => 'text',
        ],
        [
            'name' => 'content',
            'label' => 'Testimonio',
            'type' => 'textarea',
        ],
    ],
    'new_item_label' => 'Añadir Testimonio', // Label for the "Add item" button
    'init_rows' => 1, // Number of rows to initialize with
    'min_rows' => 1, // Minimum number of rows
    'max_rows' => 15, // Maximum number of rows
],

Additional Information:

I am aware that the withFiles attribute can accept an array of options, including setting the disk, but this does not work either.

Steps to Reproduce:

  1. Create a repeatable field with an upload subfield as shown in the code above.
  2. Attempt to save the form with an image uploaded in the author_image field.
  3. Observe that the image is not saved in the specified disk.

Expected Behavior:

The image should be saved in the specified disk when the form is submitted.

Backpack, Laravel, PHP, DB version

  • backpack/crud: ^6.7 ( 6.7.24 )
  • backpack/pro: ^2.2 ( 2.2.11 )
  • php: 8.2.18
  • laravel: ^11.0 ( 11.19.0 )

Bypass the error

Actually searching for a solution, if I find one I will add it in the comments section below.


Maybe the error is because i'm doing something wrong with the repeatable field.
I hope this helps you.
Thannks in advance ❤️

@adrinro adrinro added the triage label Sep 12, 2024
Copy link

welcome bot commented Sep 12, 2024

Hello there! Thanks for opening your first issue on this repo!

Just a heads-up: Here at Backpack we use GitHub Issues only for tracking bugs. Talk about new features is also acceptable. This helps a lot in keeping our focus on improving Backpack. If you issue is not a bug/feature, please help us out by closing the issue yourself and posting in the appropriate medium (see below). If you're not sure where it fits, it's ok, a community member will probably reply to help you with that.

Backpack communication channels:

  • Bug Reports, Feature Requests - GitHub Issues (here);
  • Quick help (How do I do X) - Gitter Chatroom;
  • Long questions (I have done X and Y and it won't do Z wtf) - Stackoverflow, using the backpack-for-laravel tag;
  • Showing off something you've made, asking for opinion on Backpack/Laravel matters - Reddit;

Please keep in mind Backpack offers no official / paid support. Whatever help you receive here, on Gitter, Slack or Stackoverflow is thanks to our awesome awesome community members, who give up some of their time to help their peers. If you want to join our community, just start pitching in. We take pride in being a welcoming bunch.

Thank you!

--
Justin Case
The Backpack Robot

@karandatwani92
Copy link
Contributor

karandatwani92 commented Sep 13, 2024

Hey @adrinro

The disk attribute is not at the right place. It should be:

[
   'name' => 'author_image',
   'label' => 'Imagen',
   'type' => 'upload',
   'withFiles' => ['disk' => 'testimonial'],
]

You can know more possible configurations here.

@adrinro
Copy link
Author

adrinro commented Sep 16, 2024

Hi @karandatwani92

I aware that the withFiles attribute should be used as you show, but as I say in the isseu I also try that and still not working for me 😅

@VesninAndrey
Copy link

It's strange but rename 'fields' to 'subfields' helped for me.

Like this:

[
    'name' => 'testimonials',
    'label' => 'Testimonios',
    'type' => 'repeatable',
    'subfields' => [
        [

Also I've noticed that for a "relation" repeatable field this line pass a wrong model.

src/app/Library/Uploaders/Support/RegisterUploadEvents.php#120

So I had to do
$this->crud->entry = null;

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Status: No status
Development

No branches or pull requests

4 participants