Copied to clipboard

Flag this post as spam?

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


  • Chester Campbell 98 posts 209 karma points
    Jan 14, 2015 @ 18:21
    Chester Campbell
    0

    Codefirst form error "Sequence contains no matching element", multiple fields in db

    Hi,

    My setup is:

    • Umbraco 7.1.6
    • Contour 3.0.23

    I'm trying to build a codefirst form that contains conditions. I'll post the code below. When I build and run the site I get the following error:

    Sequence contains no matching element
    
    Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. 
    
    Exception Details: System.InvalidOperationException: Sequence contains no matching element
    
    Stack Trace: 
    [InvalidOperationException: Sequence contains no matching element]
       System.Linq.Enumerable.Single(IEnumerable`1 source, Func`2 predicate) +2614017
       Umbraco.Forms.CodeFirst.FormManager.SynchronizeForm(Type typeForm) in f:\TeamCity\buildAgent\work\3b0e3c3a4846294b\Umbraco.Forms.CodeFirst\FormBuilder\FormManager.cs:501
       Umbraco.Forms.CodeFirst.FormManager.SynchronizeForms() in f:\TeamCity\buildAgent\work\3b0e3c3a4846294b\Umbraco.Forms.CodeFirst\FormBuilder\FormManager.cs:201
       Umbraco.Forms.CodeFirst.FormManager.Synchronize() in f:\TeamCity\buildAgent\work\3b0e3c3a4846294b\Umbraco.Forms.CodeFirst\FormBuilder\FormManager.cs:24
       Umbraco.Forms.CodeFirst.UmbracoManager.Synchronize() in f:\TeamCity\buildAgent\work\3b0e3c3a4846294b\Umbraco.Forms.CodeFirst\UmbracoManager.cs:36
       Umbraco.Forms.CodeFirst.UmbracoManager.SynchronizeIfNotSynchronized() in f:\TeamCity\buildAgent\work\3b0e3c3a4846294b\Umbraco.Forms.CodeFirst\UmbracoManager.cs:21
       Umbraco.Forms.CodeFirst.ContourFormBuilderHttpModule.context_BeginRequest(Object sender, EventArgs e) in f:\TeamCity\buildAgent\work\3b0e3c3a4846294b\Umbraco.Forms.CodeFirst\ContourFormBuilderHttpModule.cs:27
       System.Web.SyncEventExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +136
       System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +69
    
    Version Information: Microsoft .NET Framework Version:4.0.30319; ASP.NET Version:4.0.30319.34237
    

    When I look in the database (SqlCE) I see that the table UFFieldsets has duplicate entries for my form's fieldset. And the table UFFields has duplicate entries for each of the form's fields.

    What is going on and how can I fix it?

    Here is my codefirst form:

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Web;
    using Umbraco.Forms.CodeFirst;
    using Umbraco.Forms.Core;
    using Umbraco.Forms.Core.Providers;
    using Umbraco.Forms.Core.Providers.FieldTypes;
    
    namespace WebApplication1.App_Code.AM.SteppedForm
    {
        [Form("SteppedForm", Id = "59d7c262-76b4-40be-bf10-fc1a4995376b",
            ShowValidationSummary = true,
            MessageOnSubmit = "Thank You!")]
        public class SteppedForm : FormBase
        {
            [Field("ContactILA", "MemberStatus",
                Caption = "Are you a current member?",
                Mandatory = true,
                RequiredErrorMessage = "Are you a current member?",
                Type = typeof(RadioButtonList),
                Prevalues = new string[2] { "Yes", "No" })]
            public string IsMember { get; set; }
    
            [Field("ContactILA", "MemberStatus",
                Caption = "Are you interested in membership?",
                Type = typeof(RadioButtonList),
                Prevalues = new string[2] { "Yes", "No" },
                EnableCondition = true,
                ConditionActionType = FieldConditionActionType.Show,
                ConditionLogicType = FieldConditionLogicType.Any)]
            [FieldConditionRule("IsMember", FieldConditionRuleOperator.Is, "No")]
            public string MembershipInterest { get; set; }
    
            [Field("ContactILA", "MemberStatus",
                Caption = "Member Number",
                EnableCondition = true,
                ConditionActionType = FieldConditionActionType.Show,
                ConditionLogicType = FieldConditionLogicType.Any)]
            [FieldConditionRule("IsMember", FieldConditionRuleOperator.Is, "Yes")]
            public string MemberNumber { get; set; }
    
            public override IEnumerable<Exception> Validate()
            {
                var e = new List<Exception>();
    
                if (this.IsMember == "Yes" && string.IsNullOrEmpty(this.MemberNumber))
                {
                    e.Add(new Exception("Please enter your member number."));
                }
    
                return e;
            }
        }
    }
    

    Thanks!

    chester

  • Dennis Aaen 4499 posts 18254 karma points admin hq c-trib
    Jan 14, 2015 @ 18:29
    Dennis Aaen
    0

    Hi Chester,

    Perhaps this post can help you to get back on track again. http://our.umbraco.org/forum/umbraco-pro/contour/54843-Creating-form-with-code-first-and-conditional-logic

    Hope this helps,

    /Dennis

  • Chester Campbell 98 posts 209 karma points
    Jan 14, 2015 @ 18:43
    Chester Campbell
    0

    @Dennis ... Thank you for the suggestion. In that thread the OP has the same problem that I do but then he later states that he fixed it but doesn't say how. I suppose I will contact the OP directly and see if he'll be willing to share info. I'll post back here with my results.

  • Dennis Aaen 4499 posts 18254 karma points admin hq c-trib
    Jan 14, 2015 @ 18:49
    Dennis Aaen
    0

    Okay, I just found a blogpost on TimĀ“s blog perhaps you can get closer to a solution looking at this http://www.nibble.be/?p=205

    /Dennis

  • Chester Campbell 98 posts 209 karma points
    Jan 14, 2015 @ 19:25
    Chester Campbell
    0

    @Dennis ... Thanks. I actually started this whole process by reading Tim's nibble.be posts. Unfortunately, I haven't found a discussion around this particular issue there.

  • Chester Campbell 98 posts 209 karma points
    Jan 15, 2015 @ 00:41
    Chester Campbell
    0

    I'm thinking the problem is with the conditional logic attributes I've attached to my class properties so I decided to build a Contour form with conditional logic using the UI to see how it works.

    Again, a clean Umbraco 7.1.6 site with Contour 3.0.23 (the latest release). I log into the backoffice and in the Contour section I create a form with three fields:

    1) Are you a member? ... radio button list with two prevalues: "Yes" and "No". Marked as mandatory.

    2) Member Number ... textfield. Conditional logic: If "Are you a member?" == "Yes" then show this field. Not mandatory.

    3) Are you interested in membership? ... radio button list with two prevalues: "Yes" and "No". Not mandatory. Conditional logic: If "Are you a member?" == "No" then show this field.

    I had to make sure my template had the following script tags (which isn't mentioned anywhere in the documentation that I can find):

      <script src="http://ajax.aspnetcdn.com/ajax/jQuery/jquery-1.8.2.min.js" type="text/javascript"></script>
      <script src="http://ajax.aspnetcdn.com/ajax/jquery.ui/1.8.22/jquery-ui.js"></script> 
      <script src="http://ajax.aspnetcdn.com/ajax/jquery.validate/1.10.0/jquery.validate.min.js" type="text/javascript"></script>   
      <script src="http://ajax.aspnetcdn.com/ajax/mvc/3.0/jquery.validate.unobtrusive.min.js" type="text/javascript"></script>
    

    Then I inserted the form into an RTE field using the insert razor macro tool. Loaded up my page in Google Chrome and ... nothing. The conditional logic doesn't work. No javascript errors.

    Now, granted I'm not using the latest and greatest Umbraco version, but still ...

Please Sign in or register to post replies

Write your reply to:

Draft