Copied to clipboard

Flag this post as spam?

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


  • Nicholas Westby 2054 posts 7100 karma points c-trib
    Dec 29, 2015 @ 18:52
    Nicholas Westby
    0

    Getting Value of nuPicker on Archetype Property

    I have an Archetype fieldset with a property on it that is a nuPicker. I can't seem to get a Picker instance from the value of that property. Consider this code:

    var one = model.GetValue<Picker>("newWindow");
    var two = model.GetValue<string>("newWindow");
    

    The value of one is null and the value of two is:

    [{"key":"True","label":"Open in New Window"}]
    

    The type of model is ArchetypeFieldsetModel. It seems as if the property value converter isn't working for some reason. I could manually deserialize the value, but this comment leads me to believe the code I am attempting to use should work: https://our.umbraco.org/projects/backoffice-extensions/archetype/sound-off/54224-Using-nuPickers-in-Archetype#comment-195142

    Comment

  • Nicholas Westby 2054 posts 7100 karma points c-trib
    Dec 29, 2015 @ 19:01
    Nicholas Westby
    0

    If it helps, here is the context in which I am trying to get the value:

    using Archetype.Models;
    using Newtonsoft.Json;
    using nuPickers;
    using Rhythm.Extensions.Helpers;
    using System;
    using System.ComponentModel;
    using System.Globalization;
    using System.Linq;
    using Types;
    using Umbraco.Core;
    
    public class LinkConverter : TypeConverter
    {
        public override bool CanConvertFrom(ITypeDescriptorContext context,
            Type sourceType)
        {
            return true;
        }
    
        public override object ConvertFrom(ITypeDescriptorContext context,
            CultureInfo culture, object value)
        {
    
            if (value is string)
            {
                value = JsonConvert.DeserializeObject<ArchetypeModel>(value as string);
            }
    
            var model = (value as ArchetypeModel).FirstOrDefault();
            var alias = model.Alias;
            if ("contentLink".InvariantEquals(alias))
            {
    
                var strNodeId = model.GetValue<string>("linkPage");
                if(!string.IsNullOrWhiteSpace(strNodeId))
                {
                    var nodeId = int.Parse(strNodeId);
                    var helper = ContentHelper.GetHelper();
                    var node = helper.TypedContent(nodeId);
                    if (node != null)
                    {
                        var suffix = model.GetValue<string>("linkSuffix");
                        var url = node.Url + suffix;
                        // null
                        var one = model.GetValue<Picker>("newWindow");
                        // [{"key":"True","label":"Open in New Window"}]
                        var two = model.GetValue<string>("newWindow");
                        return new Link()
                        {
                            Label = model.GetValue<string>("linkLabel"),
                            NewWindow = false,//TODO: Hardcoded until I can resolve a bug.
                            Title = model.GetValue<string>("linkTitle"),
                            Url = url
                        };
                    }
                }
            }
            //TODO: Other link types.
    
            return null;
        }
    
    }
    
Please Sign in or register to post replies

Write your reply to:

Draft