I've a small problem with my Asp.Net MVC.
For now I've developed a website in english, everything is working fine, all my texts are already in localization, and I've already a session based system. When I go to another language(in my case french), it changes the Thread.CurrentThread.CurrentUICulture and Thread.CurrentThread.CurrentCulture to a culture info created from "fr".
All my traductions is working, but I've a problem in one form.
In France, the decimal part is separated from the integer part with ",". The server validation works fine with it and translate "234,512"(and know transforms "234.512" too)into a double.
But the client validation doesn't accept this, it says:
"Le champ XYZ doit ĂȘtre un nombre."
So it has the correct local(because the message is translated in french), but it seems to want the number edited in "235,55".
At start I thought it wasn't a big deal, users can enter number with the "234.512" format, but the problem is for the edition of data, since the thread is in French, it fill the model with "234,512", and not "234.512", and because of that customer must change the separator on every change(event if they don't make change on this field) otherwise they get a client validation error(no call are being made when I press on the submit button, I checked several times).
So what should I do to have the client validation script for double working in the current locale?
Thank you very much!
It seems to be a problem with the jquery.validate.js (or jquery.validate.unobtrusive.js), which only accepts dots as separators.
Take a look on the following post for a solution:
http://www.mfranc.com/2011/07/05/jquery-valdiator-modyfing-decimal-separator/
or
http://www.campusmvp.net/asp-net-mvc-3-and-the-coma-in-decimals/
It is known problem. Javascript validators inside jquery doesn't allow anything except point.
The simplest way is to change jquery.validate.min.js (or so) or override custom validator inside your cshtml. Inside jquery it will be:
// http://docs.jquery.com/Plugins/Validation/Methods/number
number: function(value, element) {
//return this.optional(element) || /^-?(?:\d+|\d{1,3}(?:,\d{3})+)(?:\.\d+)?$/.test(value); <-- original
return this.optional(element) || /^-?(?:\d+|\d{1,3}(?:,\d{3})+)(?:[\.,]\d+)?$/.test(value);
},
Related
When updating prices in NopCommerce Product edit, the zeroes behind the dot is added to the number.
e.g. 440.0000 becomes 4400000
The prices is stored in a decimal type. The language used on the client machine is Danish, which normally uses ',' as decimal separator. In the Edit webpage dot '.' is used as decimal separator and it will not accept ','. By googling around I have seen that other Danes has had the same problem.
This question and answer could identify the problem and a maybe offer a solution. Can anyone tell me how to implement it in NopCommerce?
It is not an option to make any change in the NopCommerce source code, despite it's "open source", because I am trying to fix a legacy system.
The problem occurs in both Chrome and Firefox.
Depending on the version of nopCommerce you use have a look at
Global.asax.cs - SetWorkingCulture()
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
CommonHelper.SetTelerikCulture();
}
ComonHelper.cs - SetTelerikCulture()
public static void SetTelerikCulture()
{
//little hack here
//always set culture to 'en-US' (Kendo UI has a bug related to editing decimal values in other cultures). Like currently it's done for admin area in Global.asax.cs
var culture = new CultureInfo("en-US");
Thread.CurrentThread.CurrentCulture = culture;
Thread.CurrentThread.CurrentUICulture = culture;
}
The above code blocks represent nopCommerce 3.90.
It is not an option to make any change in the NopCommerce source code, despite it's "open source", because I am trying to fix a legacy system.
Since you do not want to change the nopCommerce source code, you have no choice but to use nop Admin using en-US culture.
Edit
One thing you could try is adding one of the culture scripts provided by telerik. See ~/Scripts/kendo/2014.1.318/cultures/...
Although this requires a minor change on a view (source code)
This answer just to close the question. Thanks to Raphael for his answer.
The only way to solve the problem is to set working culture and make a recompile, which as written in the question is not an option. Because I don't know if there are any custom changes in the legacy compilation.
I am developing one MVC4 application, in that there is option for language seletion in my application & based on that selected lanaguage, all label & messages are displayed.In this application i have put one required field validation of MVC, and it will display validation message in english only.I have created two different xml file for Localization in my application folder i.e Resource.resx for english lanaguage & Resource.de-DE.resx for German langauge. I have used the following code in my Model class :
[Required(ErrorMessageResourceType = (typeof(MyFolder.MyResource.Resource)), ErrorMessageResourceName= "FromDateRequiredMessage")]
[Display(Name = "FromDate", ResourceType = typeof(MyFolder.MyResource.Resource))]
public DateTime FromDate { get; set; }
So here i have Resource.resx xml file and in that i have Key is 'FromDateRequiredMessage' which is same key as in Resource.de-DE.resx german file but different value.Also i have make the follwing changes in my in web.config file for globalization :
<globalization enableClientBasedCulture="true" culture="auto" uiCulture="auto"/>
So, i want that when i select the german language from my application, then it should show me validation error in german language.But here it will show me validation message in english only.
So, now what can i do for this? Please hel me.
Please use method Application_PreRequestHandlerExecute() in your application's Global.asax file. This method will execute before any page request or its validation.
Also set the current culture value in this method.
Simple answer > nothing is wrong!
when you put culture=auto in web.config it works this way, your application will look at the header of the incoming request and look for accept languages and the order of them, so in one request in it you have something like En - Fa ... the application will select the first one and set culture an ui culture to that, so go to your browser language settings and change the order of the languages to test your application.
In order to be able to do this you will need to set the culture. So will provide the user with selection in dropdown etc which they explicity select German,English etc, this will change yoursite to be yoursite/En or yoursight/Gr etc. This article explains in well and gives sample code. http://www.codeproject.com/Articles/207602/Creating-a-Bilingual-ASP-NET-MVC3-Application-Part the part "Adding UI support to switch languages" has what you need i believe.
I am building a website where the user should have the capability of adding their School/University. I have noticed in LinkedIn, when i tried to type in my school name , it showed up a auto search box with all the schools, beginning with the letter i typed. How can i achieve the same functionality?
Do they save all the Universities in their database ? Or is there any Open webservices i can use that will show all the Schools/Universities ?
Thanks !
This feature is called "Auto Complete" and the text boxes are enabled with that. These allow you to filter the data required according to the characters you type in.
Please see this post for auto-complete feature implemented using jQuery.
Razor: Auto-complete text box inside jqGrid, How to bind values?
The example shown in that page lists all from the database. However, as a next phase, you can as well extend this feature to look for a WCF exposed service for universe of schools/colleges.
FYI" "GetSkillNameAutocomplete" is a method in the controller that takes a string parameter as an input (the search string) and gets the value(s).
Hope this helps!
I'm following the MVC 4 tutorial and I'm having some trouble with decimals and date validations.
When I try to insert a date in format dd-MM-yyyy (because it is the format defined in the Culture I have my pc in) it returns this error: The field ReleaseDate must be a date.
Also when trying to insert a decimal field like 3,01 it returns a validation message: The field xpto must be a number.
You will probably say in these case to use a dot for this but in the culture i'm using that is the thousands separator like 1.000
Is this a general problem or it is just me?
Thanks in advance for your help.
By "My PC" I assume you mean client side, the browser validation fails? See my article http://msdn.microsoft.com/en-us/library/gg674880(VS.98).aspx - jQuery moved the local specific files so you will have to hunt for them. For debugging 1. disable client side validation and verify server validation works with your local (ie, decimals and dates in your local). Then it's a matter of getting the correct client side validation. This is not really an MVC question, it's more of a "jQuery non-english date/time & decimal validation" type question. You might have to post this question again. Once you solve this, please post your solution.
To solve this quickly, create the simplest possible HTML page with jQuery validation that fails, then post the repro. You can look at the generated HTML from MVC to help you create a simple HTML page.
You can change this behavior by setting the input culture: http://msdn.microsoft.com/en-us/library/bz9tc508.aspx. You can fix it on a specific culture or use 'auto' so the browser will use the user's current culture.
I need to make a Rails form that responds back to the user live as they input fields.
Specifically, the user will need to input four decimal fields representing data from some tests our company runs. The problem is that the testers often input incorrectly (leave out a digit, or hit a '4' instead of a '1', etc).
This is easy to check, as in real life, the inputs shouldn't vary by more than 5. I would just like to send a live message back as they input saying something like "Please double check there is no mistake in your input" if the fields vary by certain conditions.
I looked at many live validations tutorials, including the one in Advanced Rails Recipes, but a) i don't need a server request for this, and b) this is not technically a validation since I only want to warn the user of the input, not prevent them from making it.
You can do this with some javascript by attaching onchange to the input fields that you want to warn users for as they're filling out the form. This way, as they move to the next field in the form, your event handler gets called, checks the value of the form field they just inputed information for, and decides whether or not to alert the user with a warning message. You wouldn't have to hit the server at all.
An example using jQuery:
$('#your_form_field').change(function () {
var isValid = false; // Validate the input's value based on some criteria
if (!isValid) {
alert("Please check your work.");
}
});
AJAX with RJS RailsCast could help. You could write RJS that is returned once from server and then executed N times on events on the client.