2016-09-12 2 views
0

WFFM 2.4バージョン151103、Sitecore 7.2を使用しています。 MVCフォームのカスタム検証を作成しました。失敗したValidationResultを返すと、フォーム上のフィールドは強調表示されず、エラーメッセージはフィールドの情報ブロックに表示されません。こちらのモデルのコードは次のとおりです。WFFM CUstom検証に失敗したときにMVCフィールドが強調表示されない

using System.Collections.Generic; 
using System.Linq; 
using System.Web; 
using System.ComponentModel; 
using System.ComponentModel.DataAnnotations; 
using Sitecore.Data.Items; 
using Sitecore.Forms.Mvc.ViewModels; 
using Sitecore.Forms.Mvc.ViewModels.Fields; 
using Sitecore.Forms.Mvc.Validators; 
using Frb.Atl.Extensions.WFFM.CustomValidators; 

namespace Frb.Atl.Extensions.WFFM.Models 
{ 
    public class TourSingleLineTextField : SingleLineTextField 
    { 
     [AtlantaTourParticipantsAttribute("tourProperty")] 
     [DataType(DataType.Text)] 
     public override string Value { get; set; } 
    } 
} 

とカスタムMVCのバリデータ:

using System; 
using System.Collections.Generic; 
using System.ComponentModel.DataAnnotations; 
using System.Globalization; 
using System.Web.Mvc; 
using System.Linq; 
using Sitecore.Diagnostics; 
using Sitecore.Forms.Mvc.Validators; 
using Frb.Atl.Extensions.WFFM.Models; 
using Sitecore.Forms.Mvc.Interfaces; 
using Sitecore.Forms.Mvc.ViewModels; 
using Sitecore.Forms.Mvc.Validators.Rules; 
using Sitecore.Forms.Mvc.ViewModels.Fields; 

namespace Frb.Atl.Extensions.WFFM.CustomValidators 
{ 
    [AttributeUsage(AttributeTargets.Property | AttributeTargets.Field, AllowMultiple = false, Inherited = true)] 
    public class AtlantaTourParticipantsAttribute : DynamicValidationBase 
    { 

     public AtlantaTourParticipantsAttribute(string tourProperty) 
     { 
      Assert.ArgumentNotNullOrEmpty(tourProperty, "tourProperty"); 
     this.TourProperty = tourProperty; 
     } 

     public string TourProperty { get; set; } 
     public string Participants { get; set; } 
     public int MaxParticipants { get; set; } 

     public string ErrorMessage = string.Empty; 

     public const int MinParticipants = 10; 

     public List<int> m60 = new List<int>(new int[] {12, 11, 10, 9, 5, 4, 3, 2, 1}); 

     protected override ValidationResult ValidateFieldValue(IViewModel TourSingleLineTextField, object value, ValidationContext validationContext) 
     { 
      var fieldModel = this.GetModel<TourSingleLineTextField>(validationContext); 
      var tourSingleLineTextField = validationContext.ObjectInstance as TourSingleLineTextField; 

      var Month = DateTime.Now.ToString("MM"); 
      int month = 0; 
      int participants = 0; 

      int.TryParse(Month, out month); 
      int.TryParse(fieldModel.Value.ToString(), out participants); 

      if (m60.Contains(month)) 
       MaxParticipants = 60; 
      else 
       MaxParticipants = 30; 

      if (participants >= 10 && participants <= MaxParticipants) 
      { 
       return ValidationResult.Success; 
      } 
      else 
      { 
       ErrorMessage = "Number of participants must be between 10 and " + MaxParticipants.ToString() + "."; 
       return new ValidationResult(ErrorMessage); 
      } 
     } 
    } 
} 

は、他の誰がWFFMでこの動作を経験していますか?あなたが持っている場合、任意の解決?

TIA

答えて

0

この問題の原因は、カスタムフィールドタイプまたは検証コードではありませんでした。問題はanalytics設定ファイルがありませんでした。フォームはカスタム検証に達する前に失敗します。分析ファイルを置き換え、検証が正しく機能し始めました。

関連する問題