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 years ago
Hi Nicolas,

I couldn't agree more. This has caused me a lot of pain with my customers also. It is a complex set of changes to apply, and I still haven't been able to make it work for UK style date formats - not completely anyway. It works everywhere except where there is also time in the editable field in the back-end. Then, after these changes, the javascript validation simply does not work, and the field is not valid - even if you try and give it US style date again.

I did recently ask for clarification of point 2 in the main suggested changes in page 5 of this thread, but have not had a reply to that, so I am still stuck with looking incompetent to my customers for not being able to switch to UK date formats. The decimal point issue is okay for us in the UK, so it is just this date issue for us.

As you say Nicolas, this should be surely an easy-to-configure setting in such an advanced version of the software as we are with nop commerce now, but the democratic nature of open source is such that a lot of people have to shout about an issue before it is considered important enough for attention. However, surely there are just some functions which should just work, and this is one of them - especially if nop wants to be truly international.

I don't have the deep understanding to even attempt a full solution to this, so I am left with following instructions that I cannot make work fully, and also with the ridiculous situation that when the next version is released, I would have to do it all again, even if I could make it work fully.

Can anyone please, please, please help fix this in the released code?

Thank you, and of course it goes without saying that I am grateful for the fantastic software that nop commerce already is and to all the people that have made this possible by contributing code.

Steve
10 years ago
Yesterday i added this line on my _AdminLayout.cshtml:

Html.AppendScriptParts("~/Administration/Scripts/globalize.js");
<script src='@Url.Content("~/Administration/Scripts/cultures/globalize.culture." + Thread.CurrentThread.CurrentCulture.Name + ".js")' type="text/javascript"></script>

With all other modification on Global.asax

I have my language correctly set and files globalize.culture.fr-CH.js is correct too ( exemple, for decimal is . , for date it's dd.mm.yyyy and currency is CHF).
When i set my language, decimal become , and currency fr. ???
If i look with firebug in front end shop, i can see that my two js are add to shop too with link to administration, even if i didn't put this in code in -Root.Head.cshtml.
If i put out this code, globalization work exactly the same, that write before.
Is it me who didn't understand everything, or globalize is automatic and go to take on internet all formats ?

Except this little problem ( it's possible to work even with this, it's just more clean ;) ) i like very much NopCommerce and i think that people who developed this are very good.

Thanks
10 years ago
elimelight wrote:
Hi Nicolas,

I couldn't agree more. This has caused me a lot of pain with my customers also. It is a complex set of changes to apply, and I still haven't been able to make it work for UK style date formats - not completely anyway. It works everywhere except where there is also time in the editable field in the back-end. Then, after these changes, the javascript validation simply does not work, and the field is not valid - even if you try and give it US style date again.

I did recently ask for clarification of point 2 in the main suggested changes in page 5 of this thread, but have not had a reply to that, so I am still stuck with looking incompetent to my customers for not being able to switch to UK date formats. The decimal point issue is okay for us in the UK, so it is just this date issue for us.

As you say Nicolas, this should be surely an easy-to-configure setting in such an advanced version of the software as we are with nop commerce now, but the democratic nature of open source is such that a lot of people have to shout about an issue before it is considered important enough for attention. However, surely there are just some functions which should just work, and this is one of them - especially if nop wants to be truly international.

I don't have the deep understanding to even attempt a full solution to this, so I am left with following instructions that I cannot make work fully, and also with the ridiculous situation that when the next version is released, I would have to do it all again, even if I could make it work fully.

Can anyone please, please, please help fix this in the released code?

Thank you, and of course it goes without saying that I am grateful for the fantastic software that nop commerce already is and to all the people that have made this possible by contributing code.

Steve


Hello Steve,

I am not sure about the "fr-CH" format but for UK I have fixed this issue by following "some" of the steps only. These are detailed on page 3 but here is is again;

Step 1 - at the bottom of  _AdminLayout.cshtml page;

change
    
@(Html.Telerik().ScriptRegistrar()
            .jQuery(false)
            .jQueryValidation(false)
            )

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


Step 2 - changes on global.asax file;
As I am using version 3.1, there is only one line of code on my "global.asax" so I had to go to source file (Global.asax.cs) file and make the following change, again towards the bottom of the page/code

change
    
 var culture = new CultureInfo("en-US");

to
      
var culture = new CultureInfo("en-GB");


Just these two steps above was good enough to display the dates in dd/mm/yyy format on IE and I had no issues with the decimal prices .
However on Google chrome I also experienced an issue with the date picker so I applied the fix on the following page as below;
http://www.codeproject.com/Tips/579279/Fixing-jQuery-non-US-Date-Validation-for-Chrome

Step 3 - add the script to _AdminLayout.cshtml head tag

I have simply added the following code just before my </head> tag;

<script>
// fix date validation for chrome
    jQuery.extend(jQuery.validator.methods, {
      date: function (value, element) {
        var isChrome = window.chrome;
        // make correction for chrome
        if (isChrome) {
          var d = new Date();
          return this.optional(element) ||
          !/Invalid|NaN/.test(new Date(d.toLocaleDateString(value)));
        }
        // leave default behavior
        else {
          return this.optional(element) ||
          !/Invalid|NaN/.test(new Date(value));
        }
      }
    });
</script>


And that is it. It all worked for me. I am not sure if I ended up breaking something else but a few tests and page views with changes to prices, dates, kg, mm and similar all proved to working so far.

Have a look at the images below and hope this helps.

http://www.websunami.com/nop3.1-admin-orders.jpg
http://www.websunami.com/nop3.1-admin-product-price.jpg
10 years ago
Hello volkanozer,

Thanks for your help.

I'll try to put in en-GB, but with this problem will be that my date will be in english, which is not a problem for me, but  a little more for my customer ;)

I did all this point and date work perfectly in fr-FR, because format is dd/mm/yyyy, but with fr-CH it must be dd.mm.yyyy. If i do it, format of date is ok, but when i enter a date, it's a message which say that the field must be a date ( for example DateOfBirth).
I must find where i can change check if date is ok or not and vchange it, but i don't know where find.

With globalize, this doesn't work ( see this post https://www.nopcommerce.com/boards/t/27394/currency-format-definition.aspx). Format in my files aren't take and it's a format form i don't know where which in all my website.
10 years ago
volkanozer wrote:
Hi Nicolas,

I couldn't agree more. This has caused me a lot of pain with my customers also. It is a complex set of changes to apply, and I still haven't been able to make it work for UK style date formats - not completely anyway. It works everywhere except where there is also time in the editable field in the back-end. Then, after these changes, the javascript validation simply does not work, and the field is not valid - even if you try and give it US style date again.

I did recently ask for clarification of point 2 in the main suggested changes in page 5 of this thread, but have not had a reply to that, so I am still stuck with looking incompetent to my customers for not being able to switch to UK date formats. The decimal point issue is okay for us in the UK, so it is just this date issue for us.

As you say Nicolas, this should be surely an easy-to-configure setting in such an advanced version of the software as we are with nop commerce now, but the democratic nature of open source is such that a lot of people have to shout about an issue before it is considered important enough for attention. However, surely there are just some functions which should just work, and this is one of them - especially if nop wants to be truly international.

I don't have the deep understanding to even attempt a full solution to this, so I am left with following instructions that I cannot make work fully, and also with the ridiculous situation that when the next version is released, I would have to do it all again, even if I could make it work fully.

Can anyone please, please, please help fix this in the released code?

Thank you, and of course it goes without saying that I am grateful for the fantastic software that nop commerce already is and to all the people that have made this possible by contributing code.

Steve

Hello Steve,

I am not sure about the "fr-CH" format but for UK I have fixed this issue by following "some" of the steps only. These are detailed on page 3 but here is is again;

Step 1 - at the bottom of  _AdminLayout.cshtml page;

change
    
@(Html.Telerik().ScriptRegistrar()
            .jQuery(false)
            .jQueryValidation(false)
            )

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


Step 2 - changes on global.asax file;
As I am using version 3.1, there is only one line of code on my "global.asax" so I had to go to source file (Global.asax.cs) file and make the following change, again towards the bottom of the page/code

change
    
 var culture = new CultureInfo("en-US");

to
      
var culture = new CultureInfo("en-GB");


Just these two steps above was good enough to display the dates in dd/mm/yyy format on IE and I had no issues with the decimal prices .
However on Google chrome I also experienced an issue with the date picker so I applied the fix on the following page as below;
http://www.codeproject.com/Tips/579279/Fixing-jQuery-non-US-Date-Validation-for-Chrome

Step 3 - add the script to _AdminLayout.cshtml head tag

I have simply added the following code just before my </head> tag;

<script>
// fix date validation for chrome
    jQuery.extend(jQuery.validator.methods, {
      date: function (value, element) {
        var isChrome = window.chrome;
        // make correction for chrome
        if (isChrome) {
          var d = new Date();
          return this.optional(element) ||
          !/Invalid|NaN/.test(new Date(d.toLocaleDateString(value)));
        }
        // leave default behavior
        else {
          return this.optional(element) ||
          !/Invalid|NaN/.test(new Date(value));
        }
      }
    });
</script>


And that is it. It all worked for me. I am not sure if I ended up breaking something else but a few tests and page views with changes to prices, dates, kg, mm and similar all proved to working so far.

Have a look at the images below and hope this helps.

http://www.websunami.com/nop3.1-admin-orders.jpg
http://www.websunami.com/nop3.1-admin-product-price.jpg


Thank you for your reply volkanozer. That looks very clear instructions, and I will implement and report back to help others if this is the best solution for now. I am working with 3.2, so hopefully it will be the same. Steve
9 years ago
Hello everyone,

Someone already find a way to turn around this problem on Version 3.30?
9 years ago
in src/Presentation/Nop.Web/Administration/Views/Shared/_AdminLayout.cshtml add:

Html.AppendScriptParts("~/Scripts/kendo/2014.1.318/cultures/kendo.culture.en-GB.min.js");


(obviously change the locale to the one you need)

under

Html.AppendScriptParts("~/Scripts/kendo/2014.1.318/kendo.web.min.js");


then add:

<script type="text/javascript">
        //set kendos current culture to the "en-GB" culture script
        kendo.culture("en-GB");
</script>


(make sure the locale is the same as the one you have used above) to just before </head> tag.


in src/Libraries/Nop.Core/CommonHelper.cs

change the locale in SetTelerikCulture() to the one you want set (the same locale as used above)
9 years ago
devdecision wrote:
Someone already find a way to turn around this problem on Version 3.30?

I tried to do it almost the same way as networkfusion described above (more general way to support any culture - more info here) but without success. There were still some issues (more info here)
9 years ago
Hi Andrei,

Please can you elaborate a bit more on:

1.Grids return edited values in en-US culture (AJAX)
2.When POSTing forms (standad pages) then it returns specified theme
3.Getting "The field XXX must be a number" validation errors on standard pages in non "en-US" cultures


I would like to perform some research on the issues.

Thanks,

Robin.
9 years ago
networkfusion wrote:
Hi Andrei,

Please can you elaborate a bit more on:

1.Grids return edited values in en-US culture (AJAX)
2.When POSTing forms (standad pages) then it returns specified theme
3.Getting "The field XXX must be a number" validation errors on standard pages in non "en-US" cultures


I would like to perform some research on the issues.

Thanks,

Robin.

Hi Robin,

Thanks. Sorry for confusing. I've just updated info.

But it still does not work properly when other cultures are used (e.g. ru-RU):
1. Grids always send edited values in en-US culture (AJAX)
2. Getting "The field XXX must be a number" validation errors on standard pages
This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.