question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Data List: Custom Value Converters

See original GitHub issue

Opening an issue to follow on from a discussion with @abjerner on commit 6dd0b4d4b31aa402d5d610c42e4b244114d328df.

Is your feature request related to a problem? Please describe.

@greystate asked on the forum if it was possible for the built-in XML data source could return additional meta-data from the selected value? e.g. the Name, Icon, etc.

https://our.umbraco.com/packages/backoffice-extensions/contentment/contentment-feedback/102742-how-can-i-output-the-label-of-a-datalist-item

Currently only the Value is stored against the property, and that’s the value returned on the front-end. However we do have an interface IDataListSourceValueConverter for enabling custom object-types and values, e.g. for Enums (and in upcoming v1.1 an IPublishedContent for an Umbraco content data source).

I wonder if there is a better way to configure the type of value you would to be returned from a Data List?

Describe the solution you’d like

Currently the IDataListSourceValueConverter interface can be used on a data source to convert the value to a specific type. However this ties the data source and output object-type close together, which irks me a little. I’m wondering about the scenario where users could specify a different value type, e.g. for the Umbraco content data source, whether they would prefer to have the IPublishedContent, or the Udi, or the raw string of the UDI, or even the int?

On the data type configuration, we could have a 3rd field for “Value converter”, with options on how to configure the desired output. The default option would still be a string (and whether that’d be single or enumerable, depending on the list editor used).

I haven’t considered much on the technical implementation of this yet, I envisage an interface (much like the data source and list editor interfaces), e.g. IDataListValueConverter, which would open it up to user customisation too.

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Reactions:3
  • Comments:7 (6 by maintainers)

github_iconTop GitHub Comments

1reaction
leekellehercommented, Jul 8, 2020

Thanks @bjarnef. This is purely a prototype at the moment - nothing set in stone. 😃 Although in the case of converting values from the Umbraco Content data source, it’d only be IPublishedContent, as IPublishedElement isn’t something that is query-able with Umbraco’s APIs, (yet). But if that day may come, it’d be totally possible to do IPublishedElement too with this approach. 👍

1reaction
greystatecommented, Jul 3, 2020

@leekelleher Just want to say that this looks utterly awesome Lee!

I’d have thunk this was a giant can of worms, to be honest 😄 - I was really just thinking of how the Color Picker can be configured to either just return the hexcolor, or to return an object (tuple?) with .Color and .Label properties.

This would be all sorts of cool!

/Chriztian

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to write custom converters for JSON serialization - .NET
In this article ... This article shows how to create custom converters for the JSON serialization classes that are provided in the System.Text....
Read more >
Value Conversions - EF Core
Value converters allow property values to be converted when reading from or writing to the database. This conversion can be from one value...
Read more >
15.10 Creating and Using a Custom Converter - Java ...
15.10 Creating and Using a Custom Converter. A JavaServer Faces converter class converts strings to objects and objects to strings as required.
Read more >
Neo4j - Custom converter for field of type List
I am using Neo4j (version 3.4.1) and Spring-data-neo4j (5.0.10.RELEASE) in my application. I am also using OGM. PS: I am ...
Read more >
Binding: Value Converters
A value converter is a class whose responsibility is to convert view-model values into values that are appropriate to display in the view...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found