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

Unable to inline save related data #1170

Closed
emteknetnz opened this issue Apr 18, 2024 · 1 comment
Closed

Unable to inline save related data #1170

emteknetnz opened this issue Apr 18, 2024 · 1 comment

Comments

@emteknetnz
Copy link
Member

emteknetnz commented Apr 18, 2024

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

@GuySartorelli
Copy link
Member

PRs merged

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants