Copied to clipboard

Flag this post as spam?

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


  • Mike Taylor 155 posts 353 karma points
    Feb 05, 2011 @ 17:49
    Mike Taylor
    0

    Dynamic prevalues in the new DataEditorSettings in 4.6.1?

    I'm using 4.6.1, and have a query about the new [DataEditorSetting(...)] properties when using a usercontrolwrapper.

    I need to have two properties. The first - "Statuses" is a "Values" type, to allow a user to enter a list of possible status values. The second property - "DefaultStatus" - is a RadioButtonList from which the user should to be able to select one of the values from the first property.

    Basically, I need to be able to populate the prevalues of my "RadioButtonList" property with the contents of my "Values" property:

    The "Values" type is stored as a semi-colon separated list, and the RadioButtonList's prevalues property requires a comma-separated list, but I'm not sure how (or at what point, or whether it's even possible) to dynamically create the prevalues of the RadioButtonList from the values entered in the "Statuses" list.

    Any ideas?

    Cheers,

    Mike

  • Comment author was deleted

    Feb 09, 2011 @ 15:57

    @Mike, not possible with the default data editor settings types, but you could do it with a custom one

    Will see if I can find some time to put an example together

    For now here is some details on creating a custom data editor setting type:

    http://www.nibble.be/?p=96

  • Mike Taylor 155 posts 353 karma points
    Feb 09, 2011 @ 17:13
    Mike Taylor
    0

    Hi Tim

    Thanks for looking at this - really appreciate it.

    I've been experimenting based on your article, and am trying to create a data editor setting type which also uses a DropDownList control, but I want to populate the items of that control with the prevalues of a second type.

    Initially, I had thought of passing the name of the "Values" type to my new type in the prevalues parameter, like this:

        [DataEditorSetting("Statuses", type=typeof(umbraco.editorControls.SettingControls.Values), description="Enter list of possible statuses")]
    public string TestValues { getset; }

    [DataEditorSetting("Test", type = typeof(MT.TestDataEditorSetting.ValuesDefault), description = "Testing dropdown", prevalues="Statuses")]
    public string TestDefaultValue { getset; }

    But then, I'm not sure how to access the prevalues of the Values type... this is kind of what I was thinking:

            public override System.Web.UI.Control RenderControl(DataEditorSetting setting)
            {
                ddl.ID = setting.GetName();
                ddl.Items.Clear();

                // we have the name of the other DataEditorSetting type in the Prevalue of this type
                // want to do something like: 
                
                // Values vals = new Values(Prevalue); <--- to get a reference to the other type, but this doesn't work

                // and then:

                // foreach (string thisVal in vals.Prevalues)
                // {
                //     ddl.Items.Add(new ListItem(thisVal));
                // }
                
                return ddl;
            }

    Am I completely off track?

    Thanks,

    Mike

  • Comment author was deleted

    Feb 10, 2011 @ 09:33

    Yup would also do it like that, then you'll simply need to fetch the stored values based on the name

  • Mike Taylor 155 posts 353 karma points
    Feb 10, 2011 @ 09:51
    Mike Taylor
    0

    That's good to know :-)

    The bit I'm missing is how to fetch the stored values... is there a method I can call which will return them?

    Cheers,

    Mike

  • Comment author was deleted

    Feb 10, 2011 @ 09:57

    Yup you should be able to use

     

    umbraco.cms.businesslogic.datatype.DataEditorSettingsStorage

    use the GetSettings(int dataTypeNodeID) method to fetch all setting values and then simply select the one with the correct alias

  • Mike Taylor 155 posts 353 karma points
    Feb 10, 2011 @ 10:54
    Mike Taylor
    0

    Thanks Tim, it's now working :-)

    One follow-up question - instead of hard-coding the dataTypeNodeID in GetSettings, is is possible to work out the ID of the containing (parent?) data type from within the new DataEditorSettingType's RenderControl method?

    Thanks again,

    Mike

  • Comment author was deleted

    Feb 10, 2011 @ 13:20

    Sure, guess easiest way is to simply fetch it from the request collection (id param)

    httpcontext.current.request['id']

  • Mike Taylor 155 posts 353 karma points
    Feb 10, 2011 @ 13:32
    Mike Taylor
    0

    It's so simple when you know how! Thanks for all your help - here's the final class.

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Web;
    using System.Web.UI.WebControls;
    using umbraco.cms.businesslogic.datatype;
    using umbraco.editorControls.SettingControls;

    namespace MT.TestDataEditorSettings
    {
        public class DefaultValue : DataEditorSettingType
        {

            private System.Web.UI.WebControls.DropDownList ddl = new System.Web.UI.WebControls.DropDownList();

            private string _val = string.Empty;
            public override string Value
            {
                get { return ddl.SelectedValue; }
                set
                {
                    if (!string.IsNullOrEmpty(value))
                    {
                        _val = value;
                    }
                }
            }


            public override System.Web.UI.Control RenderControl(DataEditorSetting setting)
            {
                ddl.ID = setting.GetName();
                ddl.Items.Clear();

                // get ID of this data type from querystring
                int dataTypeId;
                if (Int32.TryParse(HttpContext.Current.Request["id"], out dataTypeId))
                {

                    // get all data editor settings for this data type
                    DataEditorSettingsStorage des = new DataEditorSettingsStorage();
                    var settings = des.GetSettings(dataTypeId);

                    // find the setting where the key matches the prevalue passed in
                    Setting<stringstring> thisSetting = settings.Find(s => s.Key == this.Prevalues[0]);
                    if (thisSetting.Key != null)
                    {
                        // split the semi-colon separated values into a string array
                        string[] listValues = thisSetting.Value.Trim(';').Split(';');
                        foreach (string thisVal in listValues)
                        {
                            // add the items into the dropdown list
                            ddl.Items.Add(new ListItem(thisVal));

                            // set the dropdown list's selected value (if applicable)
                            if (thisVal == _val) { ddl.SelectedValue = thisVal; }
                        }
                    }
                }
                return ddl;
            }
        }
    }

  • Comment author was deleted

    Feb 10, 2011 @ 13:36

    Awesome, glad I could help!

    So what's your thoughts on the whole data editor settings improvement?

Please Sign in or register to post replies

Write your reply to:

Draft