Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Pantelis 53 posts 107 karma points
    Jul 07, 2016 @ 11:09
    Pantelis
    0

    Get options from parent node in backoffice property

    Greetings,

    What I want to accomplish is have some repeater field in a node, like Archetype and then on the child node have a picker that can select any (or none) of these options.

    Kind of like the multinode treepicker but for values instead of nodes.

    Does anyone know of an extension that can do this, or should I start with a custom property editor?

    I'd appreciate if someone has faced this and can share some insight.

    Thanks,

    Pantelis

  • Ian 178 posts 752 karma points
    Jul 07, 2016 @ 13:46
    Ian
    100

    May not be what you are after but I would look at nuPickers, I used their DotNet PrefectchListPicker datatype to select options added via an archetype repeater on the root of my site. With this data type the options made available can be derived via a class.

    My code:

    public class RegionOptions : IDotNetDataSource
    {
        IEnumerable<KeyValuePair<string, string>> IDotNetDataSource.GetEditorDataItems(int contextId)
        {
            if (contextId > 0)
            {
                var umbracoHelper = new UmbracoHelper(UmbracoContext.Current);
                var currentNode = new Node(contextId);
                var homeNode = umbracoHelper.TypedContent(currentNode.GetAncestorByPathLevel(1).Id);
    
                return RetrieveRegionsFromNow(homeNode);
            }
            else
            {
                var umbracoHelper = new UmbracoHelper(UmbracoContext.Current);
    
                var homeNodeTest = umbracoHelper.TypedContentAtRoot().FirstOrDefault();
                return RetrieveRegionsFromNow(homeNodeTest);
            }
        }
    
        private IEnumerable<KeyValuePair<string, string>> RetrieveRegionsFromNow(IPublishedContent node)
        {
            if (node.HasValue("regions"))
            {
                var regions =
                    node.GetPropertyValue<ArchetypeModel>("regions")
                        .Fieldsets.Select(
                            fieldset => new KeyValuePair<string, string>(
                                Regex.Replace(fieldset.GetValue("region"), "(?: |,)", ""),
                                fieldset.GetValue("region")));
                return regions;
            }
            return Enumerable.Empty<KeyValuePair<string, string>>();
        }
    }
    

    Instead of getting the property from the home node you would obviously target the parent of 'currentNode'.

    Other than that you will have to create something bespoke yourself.

  • Pantelis 53 posts 107 karma points
    Jul 10, 2016 @ 12:41
    Pantelis
    0

    Hello Ian,

    Thanks for this, I actually went ahead with nuPickers and it was exactly what I wanted.

    Plus the DotNet datatype is super easy to configure, couldn't have done it better from scratch!

    Thank you,

    Pantelis

Please Sign in or register to post replies

Write your reply to:

Draft