i use 2 types of date formats:
- mm.yyyy
- dd.mm.yyyy
i created editor templates handle different inputs.
i know kendo has issues when using date formats aren't in selected culture. thus, validation error "the field meas date must date."
i have added code suggested. fix format issue. reason, validation on textbox fields break. validation error shown, although data entered correct. error shows little warning icon without text.
is there reason happening?
the fields in model:
[displayname("contract")] [required(errormessage="{0} required") [uihint("textinput")] [additionalmetadata("class", "green-field")] [additionalmetadata("maxlength", "10")] public string contractno { get; set; } [displayname("meas date")] [uihint("dateinput")] [additionalmetadata("class", "green-field")] [additionalmetadata("format", "dd.mm.yyyy")] public datetime measurementdate { get; set; }
editor template datetime:
@model datetime? @{ var values = viewdata.modelmetadata.additionalvalues; var name = viewdata.modelmetadata.propertyname; } @if (values["class"].tostring().equals("blue-field")) { @(html.kendo().datepickerfor(m => m) .format(values["format"].tostring()) .htmlattributes(new { @class = values["class"] }) .enable(false) .value(model) ) } else { @(html.kendo().datepickerfor(m => m) .format(values["format"].tostring()) .htmlattributes(new { @class = values["class"] + " date" }) .value(model) ) }
editor template strings:
@model string @{ var values = viewdata.modelmetadata.additionalvalues; var name = viewdata.modelmetadata.propertyname; } @if (values["class"].tostring().equals("blue-field")) { @(html.kendo().textboxfor(m => m) .htmlattributes(new { @class = values["class"].tostring() + " helper", @maxlength = values["maxlength"].tostring() }) .enable(false) .value(model) ) } else { @(html.kendo().textboxfor(m => m) .htmlattributes(new { @class = values["class"].tostring() + " helper", @maxlength = values["maxlength"].tostring() }) ) }
so after fiddling around quite bit, came solution.
since override function breaking else , site's culture being root of problem, created own custom culture , forced server , client used culture.
i used en-za culture supplied kendo, , edited date formats requirement.
within _layout.cshtml added following:
<script> $(document).ready(function () { kendo.culture("en-za"); //culture of choice $.validator.addmethod('date', function (value, element) { return this.optional(element) || kendo.parsedate(value) }); }); </script>
i added line web.config:
<globalization uiculture="en-za" culture="en-za" enableclientbasedculture="true" ></globalization>
and finally, added kendo's default validator per examples given.
this solved problem, , added benefit, binding datetime fields did not break. (i saw date 01.02.2016 (dd.mm.yyyy) bound 2 january 2016)
unfortunately, still don't know why bug occurred, seemed have solved it.
Comments
Post a Comment