1đź‘Ť
Ok, I’ve done something like this. First of all I am using an input type=”text”. Then using jQuery.numeric() I convert my input so that it only accepts numbers, and a ,
as decimal separator.
$("#field_id").numeric({ decimal : "," });
Now every time i submit my form I have some code that converts my ,
into .
so that it fits the backend logic:
$('#recipe-form').on('submit', function(){
$('.convert-separator').each(function () {
$(this).val($(this).val().replace(',','.'));
});
this.submit();
});
But I think it’s not the best solution. I think there must be a possibility to use the input type="number"
field with a ,
separator.
1đź‘Ť
You could set your locale decimal separator
UPDATE:
Didnt saw it is jquery related,
you could create new validator class for comma numbers for instance
jQuery.validator.addMethod("commanumber", function (value, element) {
return this.optional(element) || /^(\d+|\d+,\d{1,2})$/.test(value);
}, "Please specify the correct number format");
or even extend regex to support . also
- [Django]-PostgreSQL empty list VALUES expression
- [Django]-How to calculate average of some field in Django models and send it to rest API?
- [Django]-Why is Django giving me this "violates not-null constraint" error?
0đź‘Ť
You can convert the count value in your jQuery code:
dotCount = count.toString().replace(',', '.');
This replaces the comma with a dot
- [Django]-Using absolute function in Django query set order by clause
- [Django]-Language by domain in Django
0đź‘Ť
I found nice article which one can describe your problem. Author recommended to use lang attribute e.g <html lang="en-150">
or <input type="number" lang="en-150">
.
There is also a note on www.w3.org
4.10.5.2 Implemention notes regarding localization of form controls
This section is non-normative.
The formats shown to the user in date, time, and number controls is
independent of the format used for form submission.Browsers are encouraged to use user interfaces that present dates,
times, and numbers according to the conventions of either the locale
implied by the input element’s language or the user’s preferred
locale. Using the page’s locale will ensure consistency with
page-provided data.For example, it would be confusing to users if an American English
page claimed that a Cirque De Soleil show was going to be showing on
02/03, but their browser, configured to use the British English
locale, only showed the date 03/02 in the ticket purchase date picker.
Using the page’s locale would at least ensure that the date was
presented in the same format everywhere. (There’s still a risk that
the user would end up arriving a month late, of course, but there’s
only so much that can be done about such cultural differences…)
- [Django]-How to add a custom validator in a subclass that validates a parent field in Django
- [Django]-Django admin shows models name with extra "s" at the end
- [Django]-Pylint doesn't report wrong import order when using Django
- [Django]-Getting 'No field found in Account with column name ""' when creating migration initial data in a project using django-multitenant library