Copied to clipboard

Flag this post as spam?

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


  • Lewis 36 posts 116 karma points
    Nov 18, 2013 @ 14:34
    Lewis
    0

    Custom FieldType Conditional Logic Fail

    Hi all.

    I have made a custom field type to display text in my form using the below code:

        public class FreeTextFieldType : FieldType
    {
        [Umbraco.Forms.Core.Attributes.Setting("Content", prevalues = "", description = "Enter the text to display.", control = "Umbraco.Forms.Core.FieldSetting.TextArea")]
        public string Content { get; set; }
    
        public List<Object> _value;
    
        public FreeTextFieldType()
        {
            Id = new Guid("c3d48bcc-762b-4010-8727-b92a179de7ce");
            Name = "Free Text";
            Description = "A field used to display blocks of text";
            Icon = "textfield.png";
            this.RequiresScriptManager = true;
            DataType = FieldDataType.LongString;
            _value = new List<object>();
        }
    
        public override string RenderPreview()
        {
            return string.Format("<p>{0}</p>", this.Content);
        }
    
        public override string RenderPreviewWithPrevalues(List<object> prevalues)
        {
            return RenderPreview();
        }
    
    }
    

    This is working apart from the conditional logic functionality. A look into the CheckRules() Javascript method reveals that the GUID of my fieldtype is not added anywhere and as such no .show() or .hide() is being called on the field.

    Can anyone tell me how I get my field type to be included in the CheckRules() Javascript?

    Thanks in advance,

    Lewis

  • Comment author was deleted

    Nov 18, 2013 @ 15:15

    How does your View look? for the custom fieldtype

  • Lewis 36 posts 116 karma points
    Nov 18, 2013 @ 15:27
    Lewis
    0

    @using System.Web.Mvc

    @model Umbraco.Forms.Mvc.Models.FieldViewModel

     

    @Model.AdditionalSettings.FirstOrDefault(x => x.Key == "Content").Value

     

      

     

  • Lewis 36 posts 116 karma points
    Nov 20, 2013 @ 11:31
    Lewis
    0

    Any ideas?

  • Comment author was deleted

    Nov 22, 2013 @ 11:35

    Hmm is that your entire view, seems like it's not complete, maybe put it up on gist? will take a look then https://gist.github.com/

  • Lewis 36 posts 116 karma points
    Nov 22, 2013 @ 11:40
    Lewis
    0

    Hey Tim

    That was pretty much my view minus the markup.

    I realised that the reason the conditional show/hide stuff wasn't working was because I needed to add the Model ID to the element like so:

    @using System.Web.Mvc

    @model Umbraco.Forms.Mvc.Models.FieldViewModel

    <div class="large-12 columns">

        <p id="@Model.Id">@Model.AdditionalSettings.FirstOrDefault(x => x.Key == "Content").Value</p>   

    </div>

    <!-- /.columns --> 

    Thanks anyway! 

  • Comment author was deleted

    Nov 22, 2013 @ 11:41

    Ok yeah that's true :) glad it's sorted!

Please Sign in or register to post replies

Write your reply to:

Draft