Nibble

Contour code first and Conditional Logic

Another code first example, setting up field conditions when designing your form in visual studio.

There are 3 properties on the Field attribute that need to be used (EnableCondition, ConditionActionType and ConditionLogicType) then for setting up 1 or multiple rules you’ll need to decorate the property with a FieldConditionRule attribute providing it the caption of the field, the rule operator and the value.

        [Field("Leave a comment", "Your comment",
            Mandatory = true)]
        public string Name { get; set; }
 
        [Field("Leave a comment", "Your comment",
            EnableCondition = true,
            ConditionActionType = FieldConditionActionType.Show,
            ConditionLogicType = FieldConditionLogicType.Any)]
        [FieldConditionRule("Name",FieldConditionRuleOperator.Is, "Test")]
        public string Hidden { get; set; }

In this case the field with caption hidden will only be shown if the value of the field with caption Name is test

5 Comments so far

  1. Anton on March 7th, 2013

    Hi

    How would you go about adding conditional logic to enable and disable the submit button.

    Lets say on Accepting Terms and conditions checkbox to enable the submit button.

    Thanks

  2. Martin on April 16th, 2013

    Hi Tim,

    I’m experimenting with the conditional logic thingy. Great that its available.
    Only it doesnt seem to work. Do I need to activate some kind of Javascript plugin or something?

    I’ve set the rules, but on the frontend it just shows all fields whatever I do.

    (am still running in trial mode, maybe thats the issue?

    hope to hear from you soon.
    Martin

  3. Dan on May 28th, 2013

    I’m also experiencing the same issue as you Martin. Allows me to insert the logic but the form seems to ignore it and shows every field.

    I’m using Contour 3.0.11 and Umbraco 4.11.8

  4. Tim Geyssens on May 31st, 2013

    @Martin and Dan, are you using the razor macro since conditional logic isn’t supported by the usercontrol one…

  5. baby massage tips for wind on May 6th, 2014

    Hello there! This is kind of off topic but I need
    some advice from an established blog. Is it very
    difficult to set up your own blog? I’m not very techincal but
    I can figure things out pretty quick. I’m thinking about making my own but I’m not sure where to begin.

    Do you have any ideas or suggestions? Thank you

Leave a Reply