2017-08-15 144 views
0

INPUT ELEMENTS中的消息从数据注释中正确填充,但KendoValidator似乎创建了一些不同的东西。Kendo验证器显示组合框的错误默认消息

  • 问:为什么会发生这种情况?
  • 问:我该如何解决? - 我愿意通过JavaScript
  • 更新

为了简单起见,让我们只看下拉菜单之一... ...

HTML:
注意如何data-val-required包含实际的正确的信息?

<span class="k-widget k-combobox k-header" style="width: 100%;"> 
    <span tabindex="-1" unselectable="on" class="k-dropdown-wrap k-state-default input-validation-error"> 
     <input name="Entity.DeviceTypeId_input" class="k-input k-valid" type="text" autocomplete="off" role="combobox" aria-expanded="false" placeholder="Select Device Type..." tabindex="0" aria-disabled="false" aria-readonly="false" aria-autocomplete="both" aria-owns="Entity_DeviceTypeId_listbox" aria-busy="false" aria-activedescendant="bec66a14-dad2-4632-84ba-02a9e3b5a10d" style="width: 100%;"> 
     <span tabindex="-1" unselectable="on" class="k-select"> 
      <span unselectable="on" class="k-icon k-i-arrow-s" role="button" tabindex="-1" aria-controls="Entity_DeviceTypeId_listbox">select</span> 
     </span> 
    </span> 
    <input data-val="true" data-val-number="The field DeviceTypeId must be a number." data-val-required="Device Type is required." id="Entity_DeviceTypeId" name="Entity.DeviceTypeId" required="required" style="width: 100%; display: none;" type="text" aria-required="true" data-role="combobox" aria-disabled="false" aria-readonly="false" aria-invalid="true" class="k-invalid"> 
</span> 

DATA译注:
正如你所看到的,在data-val-required的消息是正确的......

public class DeviceAnnotations 
{ 
    [Required(ErrorMessage = "Device Type is required.")] 
    public object DeviceTypeId { get; set; } 

    [Required(ErrorMessage = "State is required.")] 
    public object StateId { get; set; } 
} 

JAVASCRIPT:
我打开更新的JavaScript,但我宁愿明白为什么&哪里有错误消息来自...

var validationRoutine = { 
    validate: function (e) { 

     var comboBoxes = $(".k-combobox"); 

     $.each(comboBoxes, function (key, value) { 

      var $input = $(value).find("input.k-invalid"); //<-- this is where Kendo foolishly places k-invalid 
      var $span = $(this).find("span.k-dropdown-wrap"); //<-- this span controls the dropdown's appearance. 

      if ($input.length > 0) { // k-invalid exists... 
       $span.addClass("input-validation-error"); 
       return; 
      } 

      $span.removeClass("input-validation-error"); 
     }); 
    } 
}; 

$('form').kendoValidator(validationRoutine); 

截屏:
enter image description here

+0

你可以试试'$( “形式”)。kendoValidator()。数据( “kendoValidator”)。验证()'没有任何常规?这是正确的吗? – ibubi

回答

0

不知道这一点,但它发生,因为你有required属性,它表示基于错误信息的name="Entity.DeviceTypeId"

实体DeviceTypeId是必需的

你能请试试addi ng

validationMessage="Device Type is required." 

到您的input

我认为这应该工作,我已经用它,但不是在asp

+0

这没有奏效。而且,它有点有道理,它不会因为那么在“验证初始化器”选项中有一个“消息”集合就没有意义。谢谢您的帮助 –

相关问题