0

I'm using asp.net mvc 4.5, Nopcommerce 3.1 and i try to change culture to vi-VN. So far i got over the decimal problem by following MVC 3 jQuery Validation/globalizing of number/decimal field (globalize.culture.vi-VN.js).

However i have a problem with datetime, specifically only happen in Chrome. IE and firefox work just fine. date format like 30/11/2013 won't work in Chrome.

So far, i've set up:

in Global.asax

 var culture = new CultureInfo("vi-VN");
                Thread.CurrentThread.CurrentCulture = culture;
                Thread.CurrentThread.CurrentUICulture = culture;

In adminlayout

<script src="~/Administration/Scripts/globalize.js"></script>
   <script src="~/Administration/Scripts/globalize.culture.vi-VN.js"></script>

    <script type="text/javascript">
        $.validator.methods.number = function (value, element) {
            return this.optional(element) ||
                !isNaN(Globalize.parseFloat(value));
        }
        $.validator.methods.date = function (value, element) {
            return this.optional(element) || Globalize.parseDate(value);
        }
        $(document).ready(function () {
            Globalize.culture('vi-VN');
        });

        jQuery.extend(jQuery.validator.methods, {
            range: function (value, element, param) {
                //Use the Globalization plugin to parse the value        
                var val = $.global.parseFloat(value);
                return this.optional(element) || (
                    val >= param[0] && val <= param[1]);
            }
        });
    </script>
    @(Html.Telerik().ScriptRegistrar()
                  .jQuery(false)
                  .jQueryValidation(false)
                   .Globalization(true)

In View:

@Html.EditorFor(model => model.PackedDateUtc) => which will be rendered using Telerik datetimePicker

Datime.cshtml (EditorTemplates)
@model DateTime
@using Telerik.Web.Mvc.UI

@(Html.Telerik().DateTimePicker()
        .Name(ViewData.TemplateInfo.GetFullHtmlFieldName(string.Empty))
        .Value(Model > DateTime.MinValue? Model : DateTime.Today)
)

=>validation error message: the field PackedDateUtc must be a date. (wrong format).

Anyway to fix the jquery validation ?

Thanks.

Community
  • 1
  • 1
nam vo
  • 3,271
  • 12
  • 49
  • 76

0 Answers0