Copied to clipboard

Flag this post as spam?

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


  • Simon Dingley 1474 posts 3451 karma points c-trib
    Nov 17, 2011 @ 12:43
    Simon Dingley
    0

    Custom Fiedld Type Not Appearing in DropDown

    I've just created my first custom field type and uploaded the dll to the server however it is not currently available for selection. I followed the developer docs and a copy of my class can be seen below - did I miss something obvious?

    namespace ProlificNotion.Umbraco.Contour.FieldTypes
    {
        using System;
        using System.Collections.Generic;
        using System.Globalization;
        using System.Web.UI.WebControls;
    
        using global::Umbraco.Forms.Core;
    
        /// <summary>
        /// Defines the CountryList FieldType for Umbraco Contour
        /// </summary>
        public class CountryDropDownList : FieldType
        {
            /// <summary>
            /// The dropdown list control
            /// </summary>
            private readonly DropDownList ddl;
    
            /// <summary>
            /// Initializes a new instance of the <see cref="CountryDropDownList"/> class.
            /// </summary>
            public CountryDropDownList()
            {
                this.Id = new Guid("35EF2032-6F72-4C00-9515-2D93C27AA574");
                this.Name = "Country List";
                this.Description = "Renders an HTML select box with a list of countries";
    
                this.Icon = "icon_field.gif";
                this.DataType = FieldDataType.String;
    
                this.ddl = new DropDownList();
                this.FillWithISOCountries(this.ddl, CultureInfo.InvariantCulture);
            }
    
            /// <summary>
            /// Gets or sets the editor.
            /// </summary>
            /// <value>
            /// The editor.
            /// </value>
            public override WebControl Editor
            {
                get
                {
                    return this.ddl;
                }
    
                set
                {
                    base.Editor = value;
                }
            }
    
            /// <summary>
            /// Renders the preview.
            /// </summary>
            /// <returns>A string with the markup to render in the preview</returns>
            public override string RenderPreview()
            {
                return "<select><option>United Kingdom</option></select>";
            }
    
            /// <summary>
            /// Renders the preview with prevalues.
            /// </summary>
            /// <param name="prevalues">The prevalues.</param>
            /// <returns>A string with the markup to render in the preview</returns>
            public override string RenderPreviewWithPrevalues(List<object> prevalues)
            {
                return this.RenderPreview();
            }
    
            /// <summary>
            /// Populates the list control with countries as given by ISO 4217.
            /// </summary>
            /// <param name="ctrl">The list control to populate.</param>
            /// <param name="selectedCulture">The selected culture.</param>
            private void FillWithISOCountries(ListControl ctrl, CultureInfo selectedCulture)
            {
                foreach (var cultureInfo in CultureInfo.GetCultures(CultureTypes.SpecificCultures))
                {
                    var regionInfo = new RegionInfo(cultureInfo.LCID);
                    if (ctrl.Items.FindByValue(regionInfo.TwoLetterISORegionName) == null)
                    {
                        ctrl.Items.Add(new ListItem(regionInfo.EnglishName, regionInfo.TwoLetterISORegionName));
                    }
                }
    
                var currentRegionInfo = new RegionInfo(selectedCulture.LCID);
    
                // Default the selection to the current cultures country
                if (ctrl.Items.FindByValue(currentRegionInfo.TwoLetterISORegionName) != null)
                {
                    ctrl.Items.FindByValue(currentRegionInfo.TwoLetterISORegionName).Selected = true;
                }
            }
        }
    }
  • Fabio Milheiro 74 posts 136 karma points
    Sep 26, 2012 @ 14:31
    Fabio Milheiro
    0

    Hi, I'm facing exactly the same problem now. Can you please share how you solved?

    Thanks

  • This forum is in read-only mode while we transition to the new forum.

    You can continue this topic on the new forum by tapping the "Continue discussion" link below.

Please Sign in or register to post replies