silverstripe/silverstripe-elemental

Unable to inline save related data

Closed this issue · 1 comments

After merging Validation of fields when inline saving looks like we're unable to consistently to inline save related data fields on custom blocks such as TreedropdownField and UploadField.

This will also affect the ability to inline clear a related field that currently has a value

When using the regular page save things seem to work correctly when using auto-scaffolded fields

TreedropdownField

Auto-scaffolded field with an 'ID' suffix will xhr POST:

PageElements_4_MyPageID[value] "2"
PageElements_4_MyPageID[label] "About Us"
PageElements_4_MyPageID[selected] "false"

Which will result in a 500

Removing the suffixes will not xhr POST data for the Treedropdown field at all resulting in a 200, and field will just clear itself when the react component re-renders because the database value was never updated

UploadField

Auto-scaffolded field without in an 'ID' suffix will xhr POST:

PageElements_4_MyFile[Files][0] "2"

Which results in a 200, but database isn't updated

Adding the suffix will xhr POST

PageElements_4_MyFileID[Files][0] "2"

Which results in a 500

// app/src/MyBlock;

use DNADesign\Elemental\Models\BaseElement;

class MyBlock extends BaseElement
{
    private static $has_one = [
        'MyPage' => SiteTree::class,
        'MyFile' => File::class,
    ];

    public function getCMSFields()
    {
        $fields = parent::getCMSFields();

        // remove auto-scaffolded field with an ID suffix and add in field without ID suffix
        $fields->removeByName('MyPageID');
        $fields->addFieldToTab('Root.Main', TreeDropdownField::create('MyPage', 'My Page', SiteTree::class));

        // remove auto-scaffolded field without an ID suffix and add in a field with an ID suffix
        $fields->removeByName('MyFileID');
        $fields->addFieldToTab('Root.Main', UploadField::create('MyFileID', 'My File')->setIsMultiUpload(false));

        return $fields;
    }
}

PRs

PRs merged