Reputation: 11
With a model that contains a decimal
property, this doesn't work with a locale that uses a decimal comma:
<input asp-for="Number">
<input asp-for="Number" type="number">
Code: I am used a modal for display my form and a ViewModel:
class ViewModel
{
[StringLength(56)]
public string Speciality { get; set; }
[StringLength(128)]
public string StructureLinked { get; set; }
[Required]
[AbpRadioButton(Inline = true)]
public RateType RateSelected { get; set; }
[HiddenInput]
public decimal RateGeneral { get; set; }
public decimal RateSpecific { get; set; }
}
The first issue is that the rest of the form return french validator langage as expected, but for all the properties which use decimal
the validator is in English.
The second issues is that we give a data without comma it's send and receive correctly. But if we respect the English format
as 9.8
we receive 0
.
I tried to force the loading of the file jqueryvalidator/message_fr.js or some differents fix find on web without success
Upvotes: 1
Views: 98
Reputation: 446
This sounds like the issue described here: MVC/JQuery validation does not accept comma as decimal separator
Solution:
You can overwrite the jquery validation as explained in this post: OverWrite jQuery Validator
To allow comma and dot seperator at the same time you would add this to your script:
$.validator.methods.number = function (value, element) {
return this.optional(element)
|| /^-?(?:\d+|\d{1,3}(?:\.\d{3})+)(?:[,.]\d+)?$/.test(value);
}
Be aware that this only fixes the validation in your client. The valiation might also be adopted in the backend.
Upvotes: 0