How to change date format for Admin interface?

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.
10 лет назад
But volkanozer with this solution, the money format continue working fine?
10 лет назад
devdecision wrote:
But volkanozer with this solution, the money format continue working fine?


Yes it did for me.
When I followed bubbie'e post and follow the second step below, I had errors on both price/money and date.

2.
Next you need to change validation test from "(?:\d+|\d{1,3}(?:,\d{3})+)(?:\.\d+)" to "(?:\d+|\d{1,3}(?:\.\d{3})+)(?:,\d+)"

So  I did not apply this step 2.

It is working OK for me now. Please note that I am using nopcommerce 3.1

It should work if your money format is also;

1,536.78 which is the format here in the UK. but for example in Denmark this will be I think  1.536,78 so it won't work.
10 лет назад
volkanozer

Thanks i implement what you described and it's all most working.

But exist a little problem when you try to put truncated numbers for example

in the shipping length  if you put 0.5 or 0,5 what else,  the jquery validation cause a validation telling that it's not a number!

"The field Weight must be a number."
10 лет назад
Did you follow the step below? if you have try without this step.

Next you need to change validation test from "(?:\d+|\d{1,3}(?:,\d{3})+)(?:\.\d+)" to "(?:\d+|\d{1,3}(?:\.\d{3})+)(?:,\d+)"

When I applied the step above, I have also experienced similar issues. Try without the step above.

Although I do not use the product weight, length and similar settings i have just tried to enter 10.5 and 1.5 to these fields and it worked for me.

Are you also on 3.1?

Not ideal but a quick fix could be to change your main measurement settings from cm to mm so that instead of entering 10.5, you can just enter 105 :) I know it is not ideal but possible.
10 лет назад
Yes!

Actually i'm using 3.10.

I search into the solution for this criteria "(?:\d+|\d{1,3}(?:,\d{3})+)(?:\.\d+)" and a lot of scripts result were found.

jquery.validate.min.js
telerik.all.min.js
telerik.grid.editing.min.js
jquery.validate.js

Did you change each one of then or just the jquery.validate script?
10 лет назад
When I initially search for

(?:\d+|\d{1,3}(?:,\d{3})+)(?:\.\d+)

I have found 6 files (I think) but I have changed only 4 of them. I think I have left the telerik ones. but then I experience issues with price and date. So I have searched for the new value;

(?:\d+|\d{1,3}(?:\.\d{3})+)(?:,\d+)

And I found the 4 files I have modified and simply change them back to original value.

I used the SadMan search tool which is great help tweaking the code. you can easily find any piece of text on any file.

I dont want to post to link here but search for "Sadman Search"

good luck.
10 лет назад
FYI... The "chrome" fix referred to in previous posts that uses a call to toLocaleDateString(value) doesn't really work. The toLocalDateString() method doesn't take any parameters, and the call just returns the current date, so the validation will always pass regardless of the validity of the entered date when using Chrome.

I think krainov's previous post making use of the globalize.js library is the best approach. You could also refer to the following article for more information... http://icanmakethiswork.blogspot.com.au/2012/09/globalize-and-jquery-validate.html. I believe there's also a work request open to integrate globalize support directly into the jquery.validate plugin in the future.

Basically to get this working in nopCommerce (v3.10) I did this...

Step 1. Updated Nop.Web/global.asax.cs to remove the override that forces the culture to en-US in the admin area, changing this...


            if (webHelper.GetThisPageUrl(false).StartsWith(string.Format("{0}admin", webHelper.GetStoreLocation()),
                StringComparison.InvariantCultureIgnoreCase))
            {
                //admin area

                //always set culture to 'en-US'
                //we set culture of admin area to 'en-US' because current implementation of Telerik grid
                //doesn't work well in other cultures
                //e.g., editing decimal value in russian culture
                var culture = new CultureInfo("en-US");
                Thread.CurrentThread.CurrentCulture = culture;
                Thread.CurrentThread.CurrentUICulture = culture;
            }
            else
            {
                //public store
                var workContext = EngineContext.Current.Resolve<IWorkContext>();
                if (workContext.CurrentCustomer != null && workContext.WorkingLanguage != null)
                {
                    var culture = new CultureInfo(workContext.WorkingLanguage.LanguageCulture);
                    Thread.CurrentThread.CurrentCulture = culture;
                    Thread.CurrentThread.CurrentUICulture = culture;
                }
            }


...to this...


            var workContext = EngineContext.Current.Resolve<IWorkContext>();
            if (workContext.CurrentCustomer != null && workContext.WorkingLanguage != null)
            {
                var culture = new CultureInfo(workContext.WorkingLanguage.LanguageCulture);
                Thread.CurrentThread.CurrentCulture = culture;
                Thread.CurrentThread.CurrentUICulture = culture;
            }


Step 2. Added the globalize scripts to the scripts folder (globalize.js plus a "cultures" sub-directory along with all of the culture specific scripts you require). These are available here... https://github.com/jquery/globalize

Step 3. Added the jquery.validate.globalize library to the scripts folder. This is a specialised script that allows query.validate to make use of globalise.js for its date/number validation. It's available here... https://github.com/johnnyreilly/jquery-validation-globalize

Step 4. Updated _AdminLayout.cshtml to include the globalize scripts...


    Html.AppendScriptParts("~/Administration/Scripts/admin.common.js");
    Html.AppendScriptParts("~/Administration/Scripts/jquery.validate.globalize.min.js");
    Html.AppendScriptParts("~/Administration/Scripts/jquery.validate.unobtrusive.min.js");
    Html.AppendScriptParts("~/Administration/Scripts/jquery.validate.min.js");
    Html.AppendScriptParts("~/Administration/Scripts/jquery.unobtrusive-ajax.min.js");
    var globalizeCultureScript = string.Format("~/Administration/Scripts/cultures/globalize.culture.{0}.js", this.WorkContext.WorkingLanguage.LanguageCulture);
    if (File.Exists(Request.MapPath(globalizeCultureScript)))
    {
        Html.AppendScriptParts(globalizeCultureScript);
    }
    Html.AppendScriptParts("~/Administration/Scripts/globalize.js");
    Html.AppendScriptParts("~/Administration/Scripts/jquery-1.7.1.min.js");


Step 5. Updated _AdminLayout.cshtml to add a <script> to the head section to set the culture for globalize.js. We also need to override the date validation provided in the jquery.validate.globalize.js script because nopCommerce has combined date+time fields which are not supported by this script (it only seems to handle validation of date-only values).


  <script>

        // support validation of combined date+time fields
        jQuery.extend(jQuery.validator.methods, {
            date: function (value, element) {
                return this.optional(element) ||
                    (Globalize.parseDate(value) instanceof Date) ||
                    (Globalize.parseDate(value, Globalize.culture().calendar.patterns.d + " " + Globalize.culture().calendar.patterns.t) instanceof Date);
            }
        });

        $(document).ready(function () {
            // Set Globalize to the current culture
            Globalize.culture('@(this.WorkContext.WorkingLanguage.LanguageCulture)');
        });

    </script>


Step 6. Update the call to telerik.scriptregistrar() at the bottom of the _AdminLayout.cshtml to ensure globalization is enabled in the datepickers....


    @(Html.Telerik().ScriptRegistrar()
              .jQuery(false)
              .jQueryValidation(false)
              .Globalization(true)
              )


Hope this helps!
10 лет назад
Hi,

I would be really grateful if you could expand on step 2 above, as I am having difficulty following that part. Many thanks.

Steve
10 лет назад
Hi everybody,

I work with 3.1 version.

I tried all this variant, but i still have some strange things.
I'm Swiss and i use french language with fr-CH. Currency is CHF

Language change, name of day and date format too, but currency is wrong, it's write Fr., even if i have right value in globalize.culture.js and globalize.culture.fr-CH.js. If i delete link to this two js, value stay the same even after restart application.

Somebody can tell me where are really globalize files, because i don't think that if we'll put them in administration/scripts this will work.

I have another problem with date in admin part, i can't chnage date when i'm in fr-CH, a message write that this field must be a date. Where can i modify this test ? ( i tried already with solution above)

Thanks for answer.

Best regards

David
10 лет назад
mjy78 wrote:
FYI... The "chrome" fix referred to in previous posts that uses a call to toLocaleDateString(value) doesn't really work. The toLocalDateString() method doesn't take any parameters, and the call just returns the current date, so the validation will always pass regardless of the validity of the entered date when using Chrome.

I think krainov's previous post making use of the globalize.js library is the best approach. You could also refer to the following article for more information... http://icanmakethiswork.blogspot.com.au/2012/09/globalize-and-jquery-validate.html. I believe there's also a work request open to integrate globalize support directly into the jquery.validate plugin in the future.

Basically to get this working in nopCommerce (v3.10) I did this...



This helps a lot, but now it should be included in the next release!
I have not tried this solution yet on nop, but I use the same exact methods to globalize and localize asp mvc applications with jquery validation.
Please Andrei, could you resolve this problem, my customers cannot understand that a software like nopcommerce is not able to display numeric values in the correct format...

Thanks!
This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.