silverstripe / silverstripe-elemental

Create pages in Silverstripe CMS using content blocks
http://dna.co.nz
BSD 3-Clause "New" or "Revised" License
110 stars 115 forks source link

Bug: UploadField with multiple files doesn't update form values #560

Closed bummzack closed 5 years ago

bummzack commented 5 years ago

Version: 4.0.0 with SilverStripe 4.3

Observed behavior: When files within an UploadField are modified by the user (added, removed or sorted with SortableUploadField), the changes are not visible after saving the element. The datamodel is updated correctly though, so this seems to be a frontend/react issue? Collapsing and re-opening the element displays the correct contents.

Best explained in a video: https://streamable.com/1u82m

Not sure if this is isolated to just the use of UploadField, or if other field-types are affected as well.

Steps to reproduce: Create an elemental block that has an UploadField with many files, save the element (individually or via saving the Page) and observe.

Example code for such an element:

class GalleryBlock extends BaseElement
{
    private static $many_many = [
        'Images' => Image::class,
    ];

    private static $owns = [
        'Images',
    ];

    private static $table_name = 'GalleryBlock';

    public function getCMSFields()
    {
        $this->beforeUpdateCMSFields(function (FieldList $fields) {
            $fields->removeByName('Images');
            $fields->addFieldToTab(
                'Root.Main',
                $upload = UploadField::create('Images', $this->fieldLabel('Images'))
            );
        });

        return parent::getCMSFields();
    }
}
ScopeyNZ commented 5 years ago

Thanks for the report @bummzack . Yeah this is a problem we've observed during development (with silverstripe/elemental-bannerblock) although I thought we fixed it.

We use redux-form for holding the state of forms on the client side. It seems that in this case the state is not being persisted before the DOM is replaced by the PJAX response after hitting the save button.

am071092 commented 5 years ago

This is probably the same issue as https://github.com/dnadesign/silverstripe-elemental/issues/590?

ScopeyNZ commented 5 years ago

Possibly. I'll hope to confirm this issue is the same - and therefore fixed - within the next few weeks.

ScopeyNZ commented 5 years ago

Ok it is the same issue. Unfortunately my original fix in silverstripe/asset-admin was reverted the other day as it broke other things. I'm pretty sure the fix should exist in asset-admin though so I'll have another go.

ScopeyNZ commented 5 years ago

I'm going to close this as a duplicate of #490 . I have just raised a PR in silverstripe/asset-admin that should resolve this issue.