剑道Timepickerfor格式不工作 [英] Kendo Timepickerfor formatting not working

查看:144
本文介绍了剑道Timepickerfor格式不工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有我使用一个MVC剑道Timepicker。它的工作原理只是我不能格式化时间军用时间的罚款。之后,我添加的格式军事的时候,有一次我选择验证未通过时,它告诉我它必须是一个日期。有没有一种方法格式化TimePickerFor允许军用时间?

I have an MVC Kendo Timepicker for that I am using. It works fine except that I can't format the time to Military time. After I add the formatting for Military time, once I select the time the validation doesn't pass and it tells me it must be a date. Is there a way to format the TimePickerFor to allow military time?

@using Kendo.Mvc.UI
@model DateTime?

@(Html.Kendo().TimePickerFor(m=>m)
    .Value(@Model)
    .Min("05:00")
    .Max("00:00")
    .Format("{0:HHmm}")
)

更新:这不会格式工作被改为.Format(HHMM)

Update: This doesn't work with format being changed to .Format("HHmm")

推荐答案

好了,多亏了剑道的人,我找到了答案。该脚本可以根据情况需要一些工作。我TimePickerFor处于编辑模板它坐落在与其他timepickers和数字文本框的网格。只有这种工作方式是,一旦脚本被触发,数字盒使用该脚本还验证(因此返回$ .isNumeric(input.val())线。希望这可以帮助别人了。

Ok, so thanks to the Kendo people, I found the answer. The script may need some work depending on the situation. My TimePickerFor is in an Editor Template which sits in a grid with other timepickers and numeric text boxes. Only thing with this way of working is that once the script is fired, the numeric boxes used this script also to validate (hence the return $.isNumeric(input.val()) line. Hope this helps someone else out.

TimePickerFor控制:

TimePickerFor Control:

@using Kendo.Mvc.UI
@model DateTime?

@(Html.Kendo().TimePickerFor(m=>m)
    .Value(@Model)
    .Format("HHmm")
    .HtmlAttributes(new{data_format="HHmm"})
    .ParseFormats(new[]{"HHmm"})
)

<script>
    var originDate = kendo.ui.validator.rules.mvcdate;

    kendo.ui.validator.rules.mvcdate = function(input) {
        var format = input.attr("data-format");

        if (input.val() == "") {
            return kendo.parseDate("0000", format);
        }

        if (format) {
            return kendo.parseDate(input.val(), format);
        } else {
            return $.isNumeric(input.val());
        }
    };
</script>

这篇关于剑道Timepickerfor格式不工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆