Copied to clipboard

Flag this post as spam?

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


  • Charles Zipp 20 posts 81 karma points
    May 27, 2013 @ 02:40
    Charles Zipp
    0

    Setting in custom field type not appearing in 'AdditionalSettings' property

    Hi,

    I am trying out creating a custom field type. I followed the example in this post here.

    However, when I debug my view, the Additional Settings property is always empty. Is there something im missing? 

    Any help is much appreciated!

    FieldType Source

       public class Input : FieldType
        {
            public Input()
            {
                Id = new Guid("7D94EAA1-D277-487C-8ED0-FA666AADD41D");
                Name = "Input";
                Description = "Renders an input control according to the provided input type";
                Icon = "/umbraco/Plugins/umbracoContour/images/fieldtypes/textfield.png";
                DataType = FieldDataType.String;
            }
    
            [Setting("InputType", description = "Type of input control to render", control = "Umbraco.Forms.Core.FieldSetting.TextField")]
            public string InputType { getset; }
    
            public override string RenderPreview()
            {
                return "<input type=\"" + InputType + "\" class=\"textfield\" value=\"me@yourdomain.com\" />";
            }
    
            public override string RenderPreviewWithPrevalues(List<object> prevalues)
            {
                return RenderPreview();
            }
        }

    Partial View

    @model Umbraco.Forms.Mvc.Models.FieldViewModel
    
    @{
        string type = "text";
    
        if (Model.AdditionalSettings.Any(x => x.Key == "InputType"))
        {
            type = Model
                .AdditionalSettings
                .FirstOrDefault(x => x.Key == "InputType")
                .Value;
        }
    
    }
    
    <input type="@type" name="@Model.Name" id="@Model.Id" class="text" value="@Model.Value"
    
    @{if (Model.Mandatory || Model.Validate)
      {<text>data-val="true"</text>}}
    @{if (Model.Mandatory)
      {<text> data-val-required="@Model.RequiredErrorMessage"</text>}}
    @{if (Model.Validate)
      {<text> data-val-regex="@Model.InvalidErrorMessage" data-regex="@Model.Regex"</text>}}
    
     />
  • Charles Zipp 20 posts 81 karma points
    May 27, 2013 @ 02:58
    Charles Zipp
    0

    It seems if you do not set SupportsRegEx to true, the additional settings are not created. If i set SupportsRegEx to true in my constructor, the settings are loaded. 

    Is this by design? Smells like a bug to me

    Updated code below.

        public class Input : FieldType
        {
            public Input()
            {
                Id = new Guid("7D94EAA1-D277-487C-8ED0-FA666AADD41D");
                Name = "Input";
                Description = "Renders an input control according to the provided input type";
                Icon = "/umbraco/Plugins/umbracoContour/images/fieldtypes/textfield.png";
                DataType = FieldDataType.String;
                SupportsRegex = true;
            }
    
            [Setting("InputType", description = "Type of input control to render", control = "Umbraco.Forms.Core.FieldSetting.TextField")]
            public string InputType { getset; }
    
            public override string RenderPreview()
            {
                return "<input type=\"" + InputType + "\" class=\"textfield\" value=\"me@yourdomain.com\" />";
            }
    
            public override string RenderPreviewWithPrevalues(List<object> prevalues)
            {
                return RenderPreview();
            }
        }
  • Comment author was deleted

    May 27, 2013 @ 09:48

    Yeah that's definitly a bug, added to our issue tracker, thanks for reporting! http://issues.umbraco.org/issue/CON-372

  • 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