Pregunta

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}")
)

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

¿Fue útil?

Solución

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 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>

Otros consejos

I think you have to remove the curly braces and make sure that is a valid format type. I also don't think the 0 is necessary.

Here's some formating documentation http://docs.telerik.com/kendo-ui/getting-started/framework/globalization/dateformatting

@(Html.Kendo().TimePickerFor(m=>m)
.Value(@Model)
.Min("05:00")
.Max("00:00")
.Format("yyyy/MM/dd hh:mm tt")
)

Edit: Is your max and min values correct? I don't see how that is logically correct.

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top