简体   繁体   English

Kendo对datepicker的自定义验证

[英]Kendo custom validation for datepicker

I'm having problem with kendo datepicker custom validation (There is actually not many examples found on the web for custom validation in angular way). 我遇到了kendo datepicker自定义验证的问题(实际上在网上找不到很多以角度方式进行自定义验证的例子)。 I have set the min value of the datepicker but it only works if the user choose the date from the dropdown. 我已经设置了datepicker的最小值,但只有当用户从下拉列表中选择日期时它才有效。

If the date is typed in the input field of datepicker the min value can not affect. 如果在datepicker的输入字段中键入日期,则min值不会影响。 I want to at least show the user that they have entered an invalid date. 我想至少向用户显示他们输入的日期无效。

But it seems a bit confusing for me how to do it. 但对我来说这似乎有点令人困惑。

this is the html part: (vm is my controller) 这是html部分:( vm是我的控制器)

<form name="myForm" kendo-validator="vm.validator" ng-submit="vm.validate($event)">
    <input id="systemValidityFrom" name="systemValidityFrom" data-type="date" kendo-date-picker
        k-options="vm.validityFromOption" k-ng-model="vm.nominationVM.ValidityFromDate" placeholder="Start date"
        required validationMessage="Enter a valid date" />

    <input type="image"
        src="/webapp/content/img/globalIcons/save_icon@1x.png"
        name="template-save-button"
        class="template-btn"
        id="template-save-button"
        ng-click="vm.saveChanges();" />

    <label for="template-save-button">Save</label>
</form>

This is the JS part: 这是JS部分:

vm.nominationVM = {ValidityFromDate: null};

vm.saveChanges = function () {
    if (vm.validator.validate()) {
        TemplateService.saveTemplate();
    } 
};

vm.validityFromOption = {
    min: new Date()
};

For example I want to make the entered date invalid if it is less than today (forcing the user to type a date greater than today). 例如,如果输入日期小于今天(我强制用户输入的日期大于今天),我想让输入的日期无效。

I'd be grateful if you can help me with this issue. 如果你能帮我解决这个问题,我将不胜感激。

Yes, according to Telerik, the Min and Max options are applied only on the DatePicker's calendar ( https://www.telerik.com/forums/datepicker---max-and-min ). 是的,根据Telerik的说法,Min和Max选项仅适用于DatePicker的日历( https://www.telerik.com/forums/datepicker---max-and-min )。

If you want to evaluate the direct input of the user, you'll have to create a custom rule in your validator, for an example look at this implementation: https://demos.telerik.com/kendo-ui/validator/custom-validation 如果要评估用户的直接输入,则必须在验证器中创建自定义规则,以查看此实现的示例: https//demos.telerik.com/kendo-ui/validator/custom -validation

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM