Copied to clipboard

Flag this post as spam?

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


  • Fuji Kusaka 2203 posts 4220 karma points
    Jan 13, 2014 @ 06:58
    Fuji Kusaka
    0

    Custom Label

    I have a custom label that i would like to display making use of the conditional logic in contour.

    In addittion i created a custom textField as well, and depending if any value is enter in the textField i would like to display the Label.

    Here is the code for the labelling.

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Web;
    using Umbraco.Forms.Core;
    using Umbraco.Forms.CodeFirst;
    using Umbraco.Forms.Core.Controls;
    using System.Web.UI.WebControls;
    using Umbraco.Forms.Data;


    namespace SCTextField
    {
        public class DCLabel : FieldType
        {
            [Umbraco.Forms.Core.Attributes.Setting("Allocation ", description = "Enter the text to show in the label", control = "Umbraco.Forms.Core.FieldSetting.TextField")]
            public string LabelToShow { get; set; }


            public System.Web.UI.WebControls.TextBox lblBox;
            public List<Object> Value;

            public DCLabel(){
                //Provider
                this.Id = new Guid("2c9be796-5fe0-4fa6-8896-4f73c0c55a73");
                 this.Name = "Label Allocation Text Field";
                 this.Description = "A Read Only Field use to display Allocation ";

                 this.Icon = "Label.png";
                 this.DataType = FieldDataType.Integer;

                 lblBox = new TextBox();
                 Value = new List<object>();

            }

            public override WebControl Editor
            {
                get
                {
                  
                    lblBox.Controls.Add(new System.Web.UI.LiteralControl("<p>" + umbraco.library.ReplaceLineBreaks(LabelToShow) + "</p>"));

                    if (Value.Count > 0)
                        lblBox.Text = Value[0].ToString();
                    else if (LabelToShow != null && LabelToShow != string.Empty)
                        lblBox.Text = StringHelper.ParsePlaceHolders(HttpContext.Current, LabelToShow);

                    return lblBox;
                }
                set
                {
                    base.Editor = value;
                }
            }


            public override List<object> Values
            {
                get
                {
                    if (lblBox.Text != "")
                    {
                        Value.Clear();
                        Value.Add(lblBox.Text);
                    }
                    return Value;
                }
                set
                {
                    Value = value;
                }
            }

            public override bool SupportsPrevalues
            {
                get
                {
                    return false;
                }
             
            }

            public override string RenderPreview()
            {
              
                return "<p>" + umbraco.library.ReplaceLineBreaks(LabelToShow) + "</p>";

            }


            public override string RenderPreviewWithPrevalues(List<object> prevalues)
            {
                return RenderPreview();
            }


        }
    }

     

    Can someone point out what is wrong here ?

  • Fuji Kusaka 2203 posts 4220 karma points
    Jan 13, 2014 @ 07:28
    Fuji Kusaka
    0

    Looks like even my submit is not working. I get an error when submitting the form "Input string was not in a correct format."

  • Tim Geyssens 6562 posts 15373 karma points MVP 2x c-trib
    Jan 13, 2014 @ 09:22
    Tim Geyssens
    0

    Mind sending the code then I can test, don't spot what is wrong, and copy /pasting from the forum isn't that easy ;)

  • Fuji Kusaka 2203 posts 4220 karma points
    Jan 13, 2014 @ 09:58
    Fuji Kusaka
    0

    Can you send me your email add ?

  • Tim Geyssens 6562 posts 15373 karma points MVP 2x c-trib
    Jan 14, 2014 @ 13:00
    Tim Geyssens
    0

    yeah just use tg at umbraco dot com and I'll take a look

  • 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