我在我的项目中使用剑道日期选择器。 Kendo 支持用户编辑日期,也允许自由文本。如何防止用户输入除日期之外的任何内容。
最佳答案
据我所知,您有两种选择来解决此问题。
选项 1:
创建自定义验证器: http://docs.telerik.com/kendo-ui/framework/validator/overview
选项 2:
在保存或数据更改时,您可以检查日期是否真正有效(我已将其包装在我自己的实用程序类中,以便 JQuery 不在我的 View 模型中):
<小时/>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;
};
关于javascript - Kendo 日期选择器不可编辑,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32954868/