Twill: $browserColumns not working

Created on 9 Nov 2018  路  4Comments  路  Source: area17/twill

Hi im facing another bug...

I have a CityController and a SubjectController i show the cities inside a browser field on the Subject Create/Edit page, however i have modified the "default" title field to name on the city model and added the $titleColumnKey = 'name' on the CityController, it displays correctly on the browser listing, however after saving, and refreshing the page the "titles" display as blank field here is an example:

After picking the cities and hiting Save as Draft

image

After Refreshing the page (note that the 2 records are present and persisted to db, if i manually edit the database and add a column called title: and set to hello world, it will display correct here)
image

I see the correct "title"/name on the browser listing
image

i have also tried adding this to CityController:

protected $browserColumns = [
    'title' => [
        'title' => 'name',
        'field' => 'name',
    ],
    'name' => [
        'title' => 'name',
        'field' => 'name',
    ]
];

This is the response i get from navigating to http://localhost:9090/admin/pages/cities/browser

{
    "data": [
        {
            "id": 2,
            "name": "Rio de Janeiro",
            "edit": "http://localhost:9090/admin/pages/cities/2/edit"
        },
        {
            "id": 1,
            "name": "Sao Paulo",
            "edit": "http://localhost:9090/admin/pages/cities/1/edit"
        }
    ]
}

but looks like the frontend still expecting a field named Title to be present into the response in order for it to work... any suggestion?

bug

All 4 comments

Hi @milewski,

I assume you are using the getFormFieldsForBrowser helper in the getFormFields hook of your repository, right?

If so, using your example, getFormFieldsForBrowser($object, 'cities', 'pages', 'name') should do the trick! The fourth parameter allows you to provide a different column name than title to display in already attached items. Another way to go about it is to provide a titleInBrowser accessor on your model (getTitleInBrowserAttribute()).

Regarding $browserColumns, yes, this is a regression following our complete FE revamp using Vue. It used to display more columns in the modal and fields if specified. I'm labelling this issue as a bug so that we can restore functionality as soon as possible there.

Hi @ifox,

Thanks!! etherway ways worked:

//model
public function getTitleInBrowserAttribute()
{
    return $this->name;
}

and

//repository
public function getFormFields($object) {

    $fields = parent::getFormFields($object);

    $fields['browsers']['cities'] = $this->getFormFieldsForBrowser($object, 'cities', 'pages', 'name');

    return $fields;

}

馃憤

Please get $browserColumns working again, that would be very useful as the solutions above only work with a single column whereas my understanding is that multiple columns can be added via $browserColumns (which is what I desperately need).

If there is any kind of fairly easy shortcut/hack that can let me suffix more info onto the visible label that returns into the browser field that would be amazing.

馃憢 Just wanted to bump this issue, that I had to work around too. In my case, the browser is in a block. I had to add a bunch of accessors in the model: defaultCmsImage, getAdminEditUrlAttribute, and getTitleInBrowserAttribute. Thanks.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

sebastianlenton picture sebastianlenton  路  4Comments

Gummibeer picture Gummibeer  路  5Comments

vacoup95 picture vacoup95  路  3Comments

layout-lab picture layout-lab  路  5Comments

madsem picture madsem  路  4Comments