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.

Datalist returns null from block settings

See original GitHub issue

What is the current behaviour?

We have a custom data source to select some devices / screen resolutions to hide some block elements, where we use some block settings.

public class DeviceDataSource : IDataListSource, IDataListSourceValueConverter
{
    private readonly Dictionary<string, DeviceType> _lookup;

    public DeviceDataSource()
    {
        var devices = new List<DeviceType>
        {
            new DeviceType {
                Name = "Mobile",
                Key = "mobile",
                Icon = "icon-iphone",
            },
            new DeviceType {
                Name = "Tablet",
                Key = "tablet",
                Icon = "icon-ipad",
            },
            new DeviceType {
                Name = "Desktop",
                Key = "desktop",
                Icon = "icon-display",
            },
        };
        _lookup = devices.ToDictionary(x => x.Key.ToString());
    }

    public string Name => "Devices";

    public string Description => "Data source for devices.";

    public string Icon => "icon-brick";

    public OverlaySize OverlaySize => OverlaySize.Small;

    public Dictionary<string, object> DefaultValues => default;

    public IEnumerable<ConfigurationField> Fields => default;

    public IEnumerable<DataListItem> GetItems(Dictionary<string, object> config)
    {
        return _lookup
            .Select(x => new DataListItem
            {
                Name = x.Value.Name,
                Value = x.Key,
                Icon = x.Value.Icon,
                Description = ""
            });
    }

    public Type GetValueType(Dictionary<string, object> config) => typeof(DeviceType);

    public object ConvertValue(Type type, string value) => _lookup.ContainsKey(value) == true ? _lookup[value] : null;
}

public class DeviceType
{
    public string Name { get; set; }
    public string Key { get; set; }
    public string Icon { get; set; }
}

In this use-case the content types also vary by culture, but not the element types or block settings.

This works fine when using the property directly on a Settings node (which vary by culture). However if accessing the property from a Settings element type on a block element placed in Block List on a Standard Page (which vary by culture) the property returns null instead of the selected items.

What is the expected behaviour?

The property on either block content or block settings to return the selected items.

Please tell us about your set-up:

  • Contentment version: [1.4.2]
  • Umbraco version: [8.9.0]
  • Umbraco ModelsBuilder is: [enabled]
  • Browser: [all]

Anything else?

Settings node

image

Block element settings

image

Block element

image

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:12 (5 by maintainers)

github_iconTop GitHub Comments

2reactions
leekellehercommented, May 25, 2021

@bjarnef FYI, released v1.4.3.

1reaction
bjarnefcommented, Oct 25, 2021

@leekelleher oh, that is beautiful, just what I need 😎 Combined with custom SVG icons that’s a pretty cool feature. #h5yr 🙌👏

public enum Alignment
{
    [DataListItem(Icon = "align-left")]
    [EnumMember(Value = "left")]
    Left,

    [DataListItem(Icon = "align-center")]
    [EnumMember(Value = "center")]
    Center,

    [DataListItem(Icon = "align-right")]
    [EnumMember(Value = "right")]
    Right
}

image

Read more comments on GitHub >

github_iconTop Results From Across the Web

How can I make a browser display all datalist options when ...
So if you already have value in input then nothing will be shown in datalist options except that value if it exists. It...
Read more >
Datalist help! - HTML
Hi guys! I'm having an issue on the 'forms's practice in HTML where i'm doing the make a story project. It was all...
Read more >
How to hide datalist of column value is null
Solution 1 ; grdprof" runat= ; server" OnItemDataBound= ; grdprof_ItemDataBound"> <ItemTemplate> <div> <%# Eval( ; %> <asp:Image ID= ; Image4" ...
Read more >
<datalist>: The HTML Data List element - MDN Web Docs
The <datalist> HTML element contains a set of <option> elements that represent the permissible or recommended options available to choose ...
Read more >
HTML5 Datalist: What You Need To Know
Datalists are author-provided lists of suggestions that are always displayed regardless of previous input. One caveat is that setting the ...
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