Copied to clipboard

Flag this post as spam?

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


  • Ali Sheikh Taheri 470 posts 1648 karma points c-trib
    Mar 27, 2013 @ 10:50
    Ali Sheikh Taheri
    0

    Contour 3.0.9 label datatype

    Hi 

    I am trying to add a label dataype as follow : 

    [Umbraco.Forms.Core.Attributes.Setting("Text To Show", prevalues = "", description = "Enter the text to show in the label.", control = "Umbraco.Forms.Core.FieldSetting.TextArea")]
            public string TextToShow { get; set; }
    
            [Umbraco.Forms.Core.Attributes.Setting("Hide Field Caption", prevalues = "", description = "Select to hide the label and only show the text", control = "Umbraco.Forms.Core.FieldSetting.Checkbox")]
            public string HideFieldCaption { get; set; }
    
            [Umbraco.Forms.Core.Attributes.Setting("Is Heading", prevalues = "", description = "Select to display the label as a heading", control = "Umbraco.Forms.Core.FieldSetting.Checkbox")]
            public string IsHeading { get; set; }
    
            [Umbraco.Forms.Core.Attributes.Setting("Ignore Field for Email", prevalues = "", description = "Select to not send the field in emails", control = "Umbraco.Forms.Core.FieldSetting.Checkbox")]
            public string IgnoreFieldForEmail { get; set; }
    
            public Label _lblText;
            public List<Object> _value;
    
            public TextLabel()
            {
                Id = new Guid("57ADD3AB-C3CD-464D-BCC2-3D1C05D3BF67");
                Name = "Label";
                Description = "A read-only field used to display blocks of text";
                Icon = "textfield.png";
                DataType = FieldDataType.LongString;
                _value = new List<object>();
            }
    
            public override List<object> Values
            {
                get
                {
                    return _value;
                }
                set
                {
                    _value = value;
                }
            }
    
            public override WebControl Editor
            {
                get
                {
    
                    _lblText = new Label();
                    _lblText.CssClass = "label-text";
                    if (IsHeading == "checked") _lblText.CssClass += " heading";
                    _lblText.Text = umbraco.library.ReplaceLineBreaks(TextToShow);
    
                    return _lblText;
                }
                set
                {
                    base.Editor = value;
                }
            }
    
            public override bool HideLabel
            {
                get
                {
                    return HideFieldCaption == "checked";
                }
                set
                {
                    base.HideLabel = value;
                }
            }
    
            public override bool SupportsRegex
            {
                get { return false; }
            }
    
            public override bool SupportsPrevalues
            {
                get { return false; }
            }
    
            public override string RenderPreview()
            {
                if (IsHeading == "checked")
                {
                    return string.Format("<h6>{0}</h6>", umbraco.library.ReplaceLineBreaks(TextToShow));
                }
    
                return string.Format("<p>{0}</p>", this.TextToShow);
            }
    
            public override string RenderPreviewWithPrevalues(List<object> prevalues)
            {
                return RenderPreview();
            }

    but when I render the form I get the following error : how can I just specify not to use a view for rendering?

    the partial view '/umbraco/plugins/umbracoContour/Views/Fieldtype.label.cshtml' was not found or no view engine supports the searched locations. The following locations were searched: /umbraco/plugins/umbracoContour/Views/Fieldtype.label.cshtml

    any help is much appreciated?

  • Comment author was deleted

    Mar 27, 2013 @ 10:54

    Like the error message says you'll also need a view, take a look at the existing ones in  /umbraco/plugins/umbracoContour/Views/ and then add /umbraco/plugins/umbracoContour/Views/Fieldtype.label.cshtml

  • Ali Sheikh Taheri 470 posts 1648 karma points c-trib
    Mar 27, 2013 @ 10:55
    Ali Sheikh Taheri
    0

    I've added that too but how can I read the value of my label in the view? any example?

  • Comment author was deleted

    Mar 27, 2013 @ 10:59

    That only renders the actual control, the label is outputted in the Form.cshtml

  • Ali Sheikh Taheri 470 posts 1648 karma points c-trib
    Mar 27, 2013 @ 11:08
    Ali Sheikh Taheri
    0

    it only renders the caption of the field not the Text To Show ?

  • Comment author was deleted

    Mar 27, 2013 @ 11:28

    Ah ok yeah you can access that in the fieldtype view, check the property additionalsettings

  • Ali Sheikh Taheri 470 posts 1648 karma points c-trib
    Mar 27, 2013 @ 11:40
    Ali Sheikh Taheri
    0

    Thanks Tim, addistionalSetting worked perfect, so the label is rendered properly on actual form now

    but I still "failed preview" error on Contour section. 

  • Ali Sheikh Taheri 470 posts 1648 karma points c-trib
    Mar 27, 2013 @ 11:52
    Ali Sheikh Taheri
    1

    here is what I've added in the view in case anyone else is using my code. 

    @model Umbraco.Forms.Mvc.Models.FieldViewModel
    <p>@Model.AdditionalSettings.FirstOrDefault(x => x.Key == "TextToShow").Value</p>
  • neil perrett 1 post 21 karma points
    Mar 19, 2014 @ 18:01
    neil perrett
    0

    Hi, looks great but could you let me know what files were edited or inserted and where as i am a total noob to this.

     

     

    cheers

    neil

  • Michael Lykke 12 posts 75 karma points
    Aug 05, 2014 @ 15:14
    Michael Lykke
    0

    @neil: Did you get this to work?

    I know this post is a bit old, but after upgrading Contour (to 3.0.6 and using MVC) we had this exact same issue when using the Label fieldtype from Contour Contrib. In order to make the Label fieldtype work, you just need to add the code Ali has written to a new file named FieldType.Label.cshtml, as Tim wrote, and place that file in the 'umbraco/plugins/umbracoContour/Views/'-folder

    That means the file will only consist of two lines:

    @model Umbraco.Forms.Mvc.Models.FieldViewModel
    <p>@Model.AdditionalSettings.FirstOrDefault(x => x.Key == "TextToShow").Value</p>
    

    After this, you're ready to go.

    The part about RenderPreview failed only happens when initally adding or updating the field. Values are stored correctly and shows up when you view the form in the Contour module in the backoffice (and in the frontend, of course).

    Hope this helps!

    /Michael

Please Sign in or register to post replies

Write your reply to:

Draft