Gecko
Gecko

Reputation: 1344

Umbraco Grid custom editor not persisting config to the Model

I am trying to implement a custom Umbraco Grid editor for a fixed width and height image. The config in /config/grid.editors.config.js now looks like this:

[
{
    "name": "Image",
    "alias": "media",
    "view": "media",
    "icon": "icon-picture"
},
... other default editors 
{
    "name": "Fixed width image",
    "alias": "fixedwidthimage",
    "view": "media",
    "icon": "icon-picture",
    "config": {
        "size": {
            "width": 170,
            "height": 300
        }
    }
}
]

With this in place (see the last grid editor: Fixed width image), I can select it in the grid. Everything also persists to the view. The problem is that I cannot get to the config part. It always comes up empty:

if (Model.editor.config != null && Model.editor.config.size != null)
{
    url += "?width=" + Model.editor.config.size.width;
    url += "&height=" + Model.editor.config.size.height;

    if (Model.value.focalPoint != null)
    {
        url += "&center=" + Model.value.focalPoint.top + "," + Model.value.focalPoint.left;
        url += "&mode=crop";
    }
}

Model.editor is not null and shows the correct custom editor I added in the config. But Model.editor.config is {} when evaluating the dynamic expression in Visual Studio.

Additional information: I did not do anything else then add the editor in the config as depicted above to get the custom editor working in Umbraco.

Thank you guys in advance!

Upvotes: 1

Views: 945

Answers (1)

Gecko
Gecko

Reputation: 1344

OK, I fixed it.

It just so happened that the config was added after I added an item with that editor to the grid.

So, in short, always create the config before editing the grid.

Upvotes: 1

Related Questions