Copied to clipboard

Flag this post as spam?

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


  • John C Scott 473 posts 1183 karma points
    Jul 08, 2015 @ 12:56
    John C Scott
    0

    creating very simple custom fieldtype

    using contour 3.0.7 in umbraco 4.11

    i'm trying to add a very very basic extra fieldtype, it's purpose is just to provide a link to more information, so I've based the code on the contrib label type.

    i'm not sure if there is a step I've missed, i've compiled the source (below) into a DLL which is in the sites /bin/ folder and I've added a razor file to \umbraco\plugins\umbracoContour\Views\FieldType.NextAddress.cshtml

    I've restarted the app pool, cleared cache, turned around three times and touched my toes and crossed my legs, fingers and most other superstitious activity. However... my fieldtype does not appear in the list of field types to be added.

    Is there another step I need to take?

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using Umbraco.Forms.Core;
    using Umbraco.Forms.Core.Controls;
    using System.Web.UI.WebControls;
    using System.Web;
    using Umbraco.Forms.Core.Attributes;
    
    namespace Equiniti.Web
    {
        class NextAddressLink : FieldType
        {
            public NextAddressLink()
            {
                this.Id = new Guid("c77063d8-ba26-44a9-9871-d0ed238ce72e");
                this.Name = "NextAddress";
                this.Description = "Adds a link to be used for showing an optional additional address.";
                this.Icon = "textfield.png";
                this.DataType = FieldDataType.String;
                this.Value = new List<object>();
            }
    
            public List<object> Value;
    
            [Setting("Text To Show", prevalues = "",
               description = "Enter the text to show in the link.",
               control = "Umbraco.Forms.Core.FieldSetting.TextArea")]
            public string TextToShow { get; set; }
    
            public override WebControl Editor
            {
                get
                {
                    System.Web.UI.WebControls.Panel pnl = new System.Web.UI.WebControls.Panel();
                    pnl.ID = "pnlHolder";
                    pnl.CssClass = "contourlabelfield";
                    pnl.Controls.Add(new System.Web.UI.LiteralControl("<a class=\"nextAddress\" href=\"#\">" + TextToShow + "</a>"));
                    return pnl;
                }
                set
                {
                    base.Editor = value;
                }
            }
    
            public override List<object> Values
            {
                get
                {
                    Value.Clear();
                    Value.Add(string.Empty);
                    return Value;
                }
                set
                {
                    Value = value;
                }
            }
    
            public override string RenderPreview()
            {
                return "<a class=\"nextAddress\" href=\"#\">" + TextToShow + "</a>";
            }
    
            public override string RenderPreviewWithPrevalues(List<object> prevalues)
            {
                return this.RenderPreview();
            }
    
            public override bool SupportsRegex
            {
                get { return false; }
            }
    
            public override bool SupportsPrevalues
            {
                get { return false; }
            }
        }
    }
    
  • Comment author was deleted

    Jul 08, 2015 @ 14:34

    Did you make sure to give it a unique id? Might be since you copied it's using an id of a fieldtype that is already in place

  • John C Scott 473 posts 1183 karma points
    Jul 08, 2015 @ 14:36
    John C Scott
    0

    yes - I generated the new ID in Visual Studio

  • Comment author was deleted

    Jul 08, 2015 @ 14:36

    ah try making your class public

  • Comment author was deleted

    Jul 08, 2015 @ 14:36

    so class NextAddressLink : FieldType becomes public class NextAddressLink : FieldType

  • John C Scott 473 posts 1183 karma points
    Jul 08, 2015 @ 15:57
    John C Scott
    0

    oh dear - thank you Tim

    more than slightly embarassed

    thank you very much

Please Sign in or register to post replies

Write your reply to:

Draft