Copied to clipboard

Flag this post as spam?

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


  • Jonathan Lathigee 56 posts 99 karma points
    Jun 07, 2010 @ 21:19
    Jonathan Lathigee
    0

    Custom DropDownList works; CheckBoxList doesn't

    I followed the great example at:

    http://www.richardsoeteman.net/2010/01/04/CreateACustomMacroParameterType.aspx

    for creating a custom macro parameter of type DropDownList. Few hiccups, but ultimately worked great. I tried creating a custom macro parameter of type CheckBoxList, however, and can't get it to work. I don't think it's in my code, per se, but something about the way it interacts with umbraco. The control shows up as a valid parameter type in the macro, and when I insert the macro into a template, it prompts with the 2 values, but clicking OK to insert the macro into the template does nothing and returns the javascript error:

    Error: document.forms[0][controlId] is undefined

    My code below

    Any assistance appreciated,

    Jonathan

    using System;
    using System.Web.UI.WebControls;
    using umbraco.interfaces;
    using System.Collections.Generic;

    namespace CRD.umbraco
    {
        public class PickLeftAndOrRight : CheckBoxList, IMacroGuiRendering
        {
            protected override void OnLoad(EventArgs e)
            {
                base.OnLoad(e);

                if (this.Items.Count == 0)
                {
                    this.Items.Add(new ListItem("Left", "left"));
                    this.Items.Add(new ListItem("Right", "right"));
                }
            }

            #region IMacroGuiRendering Members

            public bool ShowCaption
            {
                get { return true; }
            }

            public string Value
            {
                get
                {
                    // also tried explicitly getting value a la:
                    // return "left";
                    // and commenting out the rest

                    List<string> selectedItems = new List<string>();
                    foreach (ListItem item in this.Items)
                    {
                        if (item.Selected)
                            selectedItems.Add(item.Value);
                    }
                    return string.Join(",", selectedItems.ToArray());
                }
                set
                {
                    // also tried explicitly setting value a la:
                    // this.Items[0].Selected = true;
                    // and commenting out the rest

                    List<string> selectedItems = new List<string>(value.Split(new char[] { ',' }));

                    foreach (ListItem item in this.Items)
                    {
                        if (selectedItems.Contains(item.Value))
                            item.Selected = true;
                    }
                }
            }

            #endregion
        }
    }

     

  • Jonathan Cohen 40 posts 115 karma points
    Oct 20, 2010 @ 20:26
    Jonathan Cohen
    0

    Hi, have you had any luck with this problem, I also use Some dropdowns and they work fine, but then I use a RadioButtonList and it gets an javascript error.

    /J

Please Sign in or register to post replies

Write your reply to:

Draft