Collection link: display multiple fieldnames

Is it possible to show more fieldnames on the display?

{
    "link": "collectionname",
    "display": [
    	"fieldname_1",
    	"fieldname_2"
    ],
    "multiple": false,
    "limit": false
}
1 Like

Hi,
I want to make same, i have try a trick with an Set field for display it on a json structure, but that not work on collection link view and display “{getDisplay(link)} or {Object}” label.

I’m new on this CMS, but after viewing this post : Renderer for set field in backend
I think this features is possible with a component.

This feature seems useful. I want to show “firstname” and “lastname” of linked entities; either has no meaning by itself.

I wrote a custom collectionlink field and added a string concat function.

Usage:

Copy the modified file to /path/to/cockpit/config/tags/field-collectionlink.tag and add your display field names in brackets. The string replacement is inspired by the set renderer.

{
  "link": "persons",
  "display": "{first_name} {last_name}"
}

I didn’t test it with "multiple":true. Feel free, to send a pull request, if you find any issues.


If you use such modified files, don’t forget to copy them to remote locations… and if you ask for help on discourse, don’t forget to mention, that your issues might differ from the default behaviour. And, obviously, custom tags won’t receive updates when you update cockpit.

3 Likes

Thanks for writing that! It would help a lot.

But I’m afraid it’s not working if you refer to a field with a collection-link.

{textfield} {collectionlinkfield}

Instead of the display name the output of the 2n field is [object Object] …the first field is rendered regularly.

I’m aware that a collectionlink-field with multiple = true would be a bit tricky. But at least with false the given display name would helpful instead of nothing or that cryptic message.

Could you please have a look?

First: I didn’t use that custom field for a long time, so I’m not sure, if there may be missing updates from the core field.

You can change

str = str.replace('{'+k+'}', _entry[k]);

to

if (typeof _entry[k] == 'string') {
    str = str.replace('{'+k+'}', _entry[k]);
}

in these two places:

Now it should at least prevent that object to string conversion, but I didn’t test it.

Feel free to send a pull request - or leave some feedback here after testing it locally.