Kendo 日期选择器不可编辑

Kendo datepicker non editable

我在我的项目中使用 kendo 日期选择器。 Kendo 支持用户编辑日期,也允许自由文本。如何防止用户输入除日期以外的任何内容。

据我所知,您有两种解决此问题的方法。

选项 1:

创建自定义验证器: http://docs.telerik.com/kendo-ui/framework/validator/overview

选项 2:

保存或数据更改时,您可以检查日期是否真正有效(我将其包装在我自己的实用程序 类 中,因此 JQuery 不在我的视图模型中):


function isValidDateTimePickerDate(id, allowNullsOrBlank) {
/// <summary>Examines the date in a Telerik date time picker to see if it is valid.</summary>
/// <param name="id" type="string">A string that represents the element's id (assumes it is prefixed with # -- my utility does not assume this, but I've condensed it for this post)</param>
/// <param name="allowNullsOrBlank" type="boolean">Indicates if a null is valid</param>
if (allowNullsOrBlank == null) {
    allowNullsOrBlank = true;
}

var value = $(id).val();

// Allow the user to have null or blank?
if (value == null || value.length === 0) {
    return allowNullsOrBlank;
}

var date = kendo.parseDate(value);
if (!date) {
    return false;
}

// Dates prior to 1900 are not valid and dates lower than 1753 
// will throw database exceptions in SQL Server
if (date.getFullYear() < 1900) {
    return false;
}

return true;
};