elliot-sawyer / silverstripe-linkfield

Adds a Linkfield for gorriecoe/silverstripe-link
BSD 3-Clause "New" or "Revised" License
9 stars 25 forks source link

Errors when linking/unlinking existing Link objects #11

Closed jules0x closed 5 years ago

jules0x commented 5 years ago

When using the autocomplete field to associated an existing Link object with the current object, an error occurs (visible in chrome inspector) and the field is cleared. Once the page is refreshed, it is apparent that the linking has occurred.

A similar effect for unlinking, but no errors this time. Only a part of the field is cleared, and a page refresh is needed to see that the association has been fully removed.

I tested this on a fresh install of a cwp project using the cwp search recipe. I added a link to Page and was able to replicate the behaviour I'd experienced in another more complex project.

Is this issue the module or the dependency on HasOneField ?

jules0x commented 5 years ago
bundle.js?m=1554336154:1 

Uncaught TypeError: this.getGridField is not a function
    at init.onclick (bundle.js?m=1554336154:1)
    at s (vendor.js?m=1552959341:1)
    at HTMLDocument.<anonymous> (vendor.js?m=1552959341:1)
    at HTMLDocument.dispatch (eval at e.exports (vendor.js?m=1552959341:1), <anonymous>:3332:9)
    at HTMLDocument.eventHandle (eval at e.exports (vendor.js?m=1552959341:1), <anonymous>:2941:28)
elliot-sawyer commented 5 years ago

This might get resolved once this is merged. Let's leave this issue open, then recheck

elliot-sawyer commented 5 years ago

@jules0x can you post some sample code to reproduce the error?

jules0x commented 5 years ago

Oh I should have mentioned, I was actually using that fork. To make sure it wasn't my project code at fault, I added some linkfields onto Page.php, by copying the implementation on the ReadMe.

private static $has_one = [
        'Link1' => Link::class,
        'Link2' => Link::class
];

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

        $fields->addFieldsToTab(
            'Root.Main',
            [
                LinkField::create(
                    'Link1',
                    'Link1',
                    $this
                ),
                LinkField::create(
                    'Link2',
                    'Link2',
                    $this
                )
            ]
        );

        return $fields;
    }
}
elliot-sawyer commented 5 years ago

@jules0x I've reproduced the error, it seems to be an issue in hasonefield, which makes a call to something in gridfieldextensions:

TypeError: this.getGridField is not a function bundle.js:1:1119
    onclick (redacted)/resources/vendor/silvershop/silverstripe-hasonefield/client/dist/js/bundle.js?m=1554336154:1
    s (redacted)/resources/vendor/silverstripe/admin/client/dist/js/vendor.js?m=1552959341:1
    build_event_proxy (redacted)/resources/vendor/silverstripe/admin/client/dist/js/vendor.js?m=1552959341:1
    dispatch (redacted)/resources/vendor/silverstripe/admin/client/dist/js/vendor.js?m=1552959341 line 1 > eval:3332
    eventHandle (redacted)/resources/vendor/silverstripe/admin/client/dist/js/vendor.js?m=1552959341 line 1 > eval:2941
elliot-sawyer commented 5 years ago

I have found a fix. Two Javascript libraries were removed in hasonefield 3.0.2. Add this to your composer.json and run an update to fix: "silvershop/silverstripe-hasonefield": "3.0.1"

Please note I recently merged in support for HasOneField v3 but Packagist still needs to be updated. If you need a fix urgently you can add the github repository to your composer.json:

    "repositories": [
        {
            "type": "vcs",
            "url": "git@github.com:gorriecoe/silverstripe-linkfield.git"
        }
    ],
elliot-sawyer commented 5 years ago

@jules0x I've raised a pull request here to fix this issue: https://github.com/gorriecoe/silverstripe-linkfield/pull/12. Can you check out the issue-11 branch on your project to see if it is fixed for you?