docassemble icon indicating copy to clipboard operation
docassemble copied to clipboard

Validation for numbers no longer accepts locale-specific decimals

Open staffanm opened this issue 3 years ago • 1 comments

With the following interview:

mandatory: true
question: Locale number validation
fields:
  - Enter a decimal number: x
    datatype: number

I used to be able to enter "2,5" (ie a decimal number formatted according to the swedish locale sv_SE). In recent versions this gives validation error "You need to enter a number." (or rather "Du måste ange ett nummer." since I use swedish as the interview language). This didn't use to be the case. I can enter "2,5" if I run the above interview in 1.3.21, but not in 1.4.6 or 1.4.9 which are the versions I have readily available for testing.

The resulting input field has the attribute pattern="[\-\d.,]*" (and anything not matching this pattern, eg "2:5", results in the different validation error "Invalid format", so it seems that the intention is to accept a wider variety of decimal number formatting, but that the jquery validation plugin is more strict.

staffanm avatar Sep 21 '22 08:09 staffanm

Sorry, the current behavior is that only US-style decimals are supported. There are a lot of factors besides the pattern attribute. I spent many hours coding a system that I thought would work, so that using , as a decimal point could be a configuration option, but then I realized it was fatally flawed and I took out all of the code. I forgot exactly why it was impossible; I think limitations in the browser itself was a big issue.

jhpyle avatar Sep 23 '22 00:09 jhpyle

I understand, to solve it in a general, localizable manner would probably be very complex. I'll just solve it for my use case with a CustomDataType.

staffanm avatar Sep 26 '22 06:09 staffanm