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);
你可以試試'$( 「形式」)。kendoValidator()。數據( 「kendoValidator」)。驗證()'沒有任何常規?這是正確的嗎? – ibubi