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
    Oct 22, 2014 @ 12:52
    Fuji Kusaka
    0

    Enable Conditional Logic with Custom Field

    Can anyone explain how to get conditional logic to work with a custom field ?

    I have the following code and trying to add same http://www.nibble.be/?p=221 but cant even get the FieldConditionActionType.Show

    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 TestField
    {
        public class DCLabel : FieldType
        {
            [Umbraco.Forms.Core.Attributes.Setting("Allocation ", prevalues = "", description = "Enter the text to show in the label", control = "Umbraco.Forms.Core.FieldSetting.TextArea")]
    
            public string LabelToShow { get; set; }
    
    
            public System.Web.UI.WebControls.TextBox lblBox;
    
            public Label _lblText;
            public List<Object> Value;
    
            public DCLabel()
            {
                //Provider
                this.Id = new Guid("9a7ddf3d-442f-4537-8c73-13433007b029");
                this.Name = "Custom Label Text Field"; 
                this.Description = "A Read Only Field use to display Text ";
    
                this.Icon = "Label.png";
                this.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";
    
                    _lblText.Text = umbraco.library.ReplaceLineBreaks(LabelToShow);
                    return _lblText;
    
    
                }
                set
                {
                    base.Editor = value;
                }
    
            }
    
    
            public override bool SupportsRegex
            {
                get
                {
                    return false;
                }
            }
    
    
            public override bool SupportsPrevalues
            {
                get
                {
                    return false;
                }
    
            }
    
            public override string RenderPreview()
            {
    
                return string.Format("<h6>{0}</h6>", umbraco.library.ReplaceLineBreaks(LabelToShow));
    
            }
    
    
            public override string RenderPreviewWithPrevalues(List<object> prevalues)
            {
                return RenderPreview();
            }
    
    
        }
    }
  • Fuji Kusaka 2203 posts 4220 karma points
    Oct 22, 2014 @ 13:50
    Fuji Kusaka
    0

    Ok got this but doesnt seem to be working 

    [Umbraco.Forms.Core.Attributes.Setting("Allocation ", prevalues = "", description = "Enter the text to show in the label", control = "Umbraco.Forms.Core.FieldSetting.TextArea")]
            [Field("Hey", "Hey", EnableCondition= true, ConditionActionType = FieldConditionActionType.Show, ConditionLogicType = FieldConditionLogicType.Any)]        
            public string LabelToShow { get; set; }
  • Fuji Kusaka 2203 posts 4220 karma points
    Oct 22, 2014 @ 19:57
    Fuji Kusaka
    0

    Any suggestions on how to display a label using conditional logic ?

  • Comment author was deleted

    Oct 23, 2014 @ 10:28

    Hey Fuji,

    You can just use the UI, the attributes are used for code first forms...

  • Comment author was deleted

    Oct 23, 2014 @ 11:11

    So no need to add extra code to the label fieldtype, you should just see the conditions bit in the UI for all fieldtypes/fields

  • Fuji Kusaka 2203 posts 4220 karma points
    Oct 23, 2014 @ 17:36
    Fuji Kusaka
    0

    Hi Tim,

    Thanks but do you have any example not sure how to proceed. :( 

     

  • Comment author was deleted

    Oct 23, 2014 @ 18:03

    Add a field of type label to your field, then on the additional settings you should see the 'enable' conditions checkbox

  • Fuji Kusaka 2203 posts 4220 karma points
    Oct 23, 2014 @ 19:27
    Fuji Kusaka
    0

    Something like this ?? 

     

     [Umbraco.Forms.Core.Attributes.Setting("Allocation ", prevalues = "", description = "Enter the text to show in the label", control = "Umbraco.Forms.Core.FieldSetting.TextArea")]
            public string LabelToShow { get; set; }
    
           [FieldConditionRule("LabelToShow", FieldConditionRuleOperator.Is, "true")]
            public string hidden { get; set; }
    
  • Fuji Kusaka 2203 posts 4220 karma points
    Oct 23, 2014 @ 19:41
    Fuji Kusaka
    0

    am getting confused now!!! do you mind showing what i need to add to the cs file ?

  • Fuji Kusaka 2203 posts 4220 karma points
    Oct 23, 2014 @ 19:47
    Fuji Kusaka
    0

    now that i can see Enable Condition on the form in contour, how do i get to make it to display "Label" only if a radioBox is checked?

  • Comment author was deleted

    Oct 24, 2014 @ 10:56

    say you have a field of type radiobox with values yes/no

    then on the label field you enable conditions and set it to show if all of the following match and then add a new rule

    if radiobox field is yes , then hit the add 

    some more details here

    https://umbraco.com/follow-us/blog-archive/2012/11/7/contour-30-features-conditional-logic.aspx

  • Comment author was deleted

    Oct 24, 2014 @ 10:57

    So no need to update the cs file it is all done in the UI

  • Fuji Kusaka 2203 posts 4220 karma points
    Oct 27, 2014 @ 13:09
    Fuji Kusaka
    0

    Still no success Tim. Can you havea look at the source code ?

  • Comment author was deleted

    Oct 27, 2014 @ 13:16

    Can you tell me the values of the radiobuttonlist and how you want to setup the condition?

  • Fuji Kusaka 2203 posts 4220 karma points
    Oct 27, 2014 @ 13:23
    Fuji Kusaka
    0

    Here you are... this is the custom fieldLabel. I would like to display the fieldLabel if "jj" is checked..

  • Comment author was deleted

    Oct 27, 2014 @ 13:46

    thanks for the details, will give it a go

  • Comment author was deleted

    Oct 27, 2014 @ 14:17

    ok i see it's because the label fieldtype doesn't have an id assigned so the condition logic can't find it, should be easy to update will post details in a min, just need to test

  • Comment author was deleted

    Oct 27, 2014 @ 14:21

    In your label fieldtype view, add a surrounding div, that has the id set to @Model.Id, that should fix it

    <div id="@Model.Id">

     

    </div>

  • Comment author was deleted

    Oct 27, 2014 @ 14:24

    or add the id to an existing element, if you post label view I can take a look

  • Fuji Kusaka 2203 posts 4220 karma points
    Oct 27, 2014 @ 16:40
    Fuji Kusaka
    0

    basic simple view

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

     

     

  • Comment author was deleted

    Oct 27, 2014 @ 16:41

    ok easiest would be to add the id to the p tag so add id="@Model.Id"

  • Fuji Kusaka 2203 posts 4220 karma points
    Oct 27, 2014 @ 17:09
    Fuji Kusaka
    0

    Great looks like its working now.. thanks :) 

  • Comment author was deleted

    Oct 28, 2014 @ 10:07

    Super :)

  • Snehal Thube 21 posts 63 karma points
    Nov 22, 2016 @ 15:44
    Snehal Thube
    0

    Hi Tim,

    Currently I am using Umbraco version 7.4.3 and as per instructions in various forums, I have uninstalled contour package and installed new umbraco forms.

    Tried running package i.e. "Umbraco Forms Migration" to convert contour forms and workflows into Umbraco forms. But started getting error.

    The type initializer for 'Nested' threw an exception.

    at Umbraco.Forms.Core.Common.Singleton`1.getInstance() at Umbraco.Forms.Core.Providers.FieldTypeProviderCollection.getInstance() at Umbraco.Forms.Migration.Field.CreateFromDataReader(IRecordsReader reader) in c:\Users\timgeyssens\Documents\Visual Studio 2013\Projects\Umbraco.Forms.Migration\Umbraco.Forms.Migration\Contour\Field.cs:line 48 at Umbraco.Forms.Migration.Data.Storage.FieldStorage.GetAllFields(FieldSet fieldset) in c:\Users\timgeyssens\Documents\Visual Studio 2013\Projects\Umbraco.Forms.Migration\Umbraco.Forms.Migration\Contour\Data\FormStorage\FieldStorage.cs:line 93 at Umbraco.Forms.Migration.Data.Storage.FieldSetStorage.GetAllFieldSets(Page page) in c:\Users\timgeyssens\Documents\Visual Studio 2013\Projects\Umbraco.Forms.Migration\Umbraco.Forms.Migration\Contour\Data\FormStorage\FieldSetStorage.cs:line 44 at Umbraco.Forms.Migration.Data.Storage.PageStorage.GetAllPages(Form form) in c:\Users\timgeyssens\Documents\Visual Studio 2013\Projects\Umbraco.Forms.Migration\Umbraco.Forms.Migration\Contour\Data\FormStorage\PageStorage.cs:line 41 at Umbraco.Forms.Migration.Data.Storage.FormStorage.GetAllForms(Boolean archived) in c:\Users\timgeyssens\Documents\Visual Studio 2013\Projects\Umbraco.Forms.Migration\Umbraco.Forms.Migration\Contour\Data\FormStorage\FormStorage.cs:line 51 at Umbraco.Forms.Migration.MigrationService.Migrate(String connString) in c:\Users\timgeyssens\Documents\Visual Studio 2013\Projects\Umbraco.Forms.Migration\Umbraco.Forms.Migration\MigrationService.cs:line 26 at Umbraco.Forms.Migration.ContourToForms.Button1_Click(Object sender, EventArgs e) in c:\Users\timgeyssens\Documents\Visual Studio 2013\Projects\Umbraco.Forms.Migration\Umbraco.Forms.Migration\ContourToForms.ascx.cs:line 23

    Then I checked the logs and found there are custom field types which are causing problem to this script

    e.g. code

    public sealed class CogFilteredUpload : FieldType {

        private **Fileupload** _fu;
        private List<Object> _value = new List<object>();
    
        [Umbraco.Forms.Core.Attributes.Setting("Upload extensions",
        description = "Allowed file extensions",
        **control** = "Umbraco.Forms.Core.FieldSetting.TextField")]
        public string AllowedExtensions { get; set; }
    

    }

    Here FileUpload not working, which was a part of Umbraco.Forms.Core.Controls assembly earlier in Contour

    Umbraco.Forms.Core.Attribute.Settings no more have Control attribute

    Can you please help with alternate way on how we can fix custom fieldtypes created earlier, as those are used in most of our forms

    Thanks, Snehal

Please Sign in or register to post replies

Write your reply to:

Draft