MVC 4 Tutorial validation errors - asp.net-mvc

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.

Related

Not able to receive large list in struts 2

I have a form with 10,000 plus check boxes with each check box have a numeric value like 8757857,8755854. When I submit the form i can see the whole data is going correctly to the backend in the network but if I check in my action class I get less values (only receiving somewhere around 9900 records).
I have tried receiving it in a List and String in the Action, but its same for both.
I have tried this issue in 3 machines and the same thing is happening.
I want to know whether it's struts 2 or any other struts 2 interceptor which is truncating the values?
Paaji, Try looking into code of Check box Interceptor in Struts2. Might be you get something there.

Formatting Orbeon Date input fields

I am trying to format an input field of the type xs:date in Orbeon.
I have tried using the xxf:format attribute, but the datepicker can not understand the date when it has been modified.
The idea now was to change the javascript of Orbeon to use the xxf:unformat attribute to interpret the date and transform it back to ISO format.
I've tried changing the data.js but for some reason none of the changes can be seen.
Am I changing the wrong file?
Edit
I figured out that the xforms.js has a function 'getCurrentValue' which is being as the changes I do there are visible. Now I just need to figure out who is the one that's calling the function.
Edit:
It is the Calendar who requests the value of the input when the user clicks on the symbol. This all happens at the client side, and the generated HTML does not have the format/unformat attributes. However I want to use their value. Can I make a request to Orbeon to get it? How?
In case you're using an xf:input bound to a node of type xs:date, you can control the formatting of the date field with the oxf.xforms.format.input.date property. A few formats are supported, and if you want to add more, the best would be to follow the pattern currently used for the currently supported formats.
E.g.
[M]/[D]/[Y]
[Y]-[M01]-[D01]

Asp.Net MVC: Client data validation in double, with localization

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);
},

How do i filter and validate form fields in symfony 1.4?

Im trying to integrate a content filtering API. My plan was to use pre/post validators but I've lost may way somehow.
What i need to do is send the values to the content filtering service. If the response comes back that the content has been filtered it will also return a modified value for the field (basic profanity filtering... matches are replace with asterisks). Thats all well and good i can throw validation errors no problem - simple stuff.
However i dont want just throw errors. What needs to happen is that validation errors are thrown as normal, but the values are modified in the form for re-display.
Basically if someone posts something naughty i want them to get a validation error saying their post has been modified, they can re-submit the now "clean" post, or they can go about editing it to make it clean without the word replacements.
But do clean on a validator either throws an error OR returns cleaned values, not both. How can i go about implementing both? This will be used on many different forms with many different field names, so modifying methods on the form or a form base class isnt really an option - it needs to happen in the validation sub-framework somehow.
You can adjust this plugin for your needs http://www.symfony-project.org/plugins/WebPurifyPlugin

How to add HyperLink in ModelState.AddModelError

i want to add a hyperlink in my message like
ModelState.AddModelError("_FORM", "Please report this error Click Here");
Im using asp.net mvc 2. How can i do this?
The problem is that the ValidationMessage and ValidationSummary methods internally use the SetInnerText() method which automatically encodes the values you have saved in the Model Errors.
Like queen3 suggests, you'll have to write your own versions of these methods to overcome this.
You can see original methods in the MVC2 source code here.
Replace tagNameHere.SetInnerText(value) with tagNameHere.InnerHtml = value
Important Note: Please make sure you take great care with where the information displayed in these messages comes from, you're allowing html now, so you're susceptible to Cross Site Scripting

Resources