Forum OpenACS Development: ad_form & international decimal separator

Hi,

I've been thinking how to handle decimal numbers when using ad_form & template::form API with central european locale settings ( e.g. numbers in the format 1.200,00 ).

At the moment, if I switch the lang to fr_FR and if a user types, for example, 1200,00. The ad_form validation for a float widget doesn't work returning a message 'Invalid decimal number "1200,00"'.

I've found that the template::data::validate::float (on acs-templating/tcl/data-procs.tcl) is not picking the decimal separator from acs-lang. I presume it is expecting to receive the openacs canonical representation for that number but it is not. It seems that the template system is not translating the localized numbers to the canonical representation.

I hacked that validation proc to quickly translate the value for that number and it seems to be working but I'm not sure if this is the best place to do this or maybe this has already been done in a better way.

Have ever had this issue?

Thanks in advance!

Collapse
Posted by Dave Bauer on
This sounds like the right place to fix the validation.

Next is the question of which format the numbers are stored in the database.

To fix that you'd need to use the transform procedure for the float widget.

Then of course you'd need to also localize the decimal on output as well.

Collapse
Posted by Enrique Catalan on
Numbers are stored in the DB using American format and yes, you're right. I'd need to translate the number to the canonical form, then validate it and finally, localize it again if we need to display an error message but if the validation goes ok, leave it in the canonical form to be inserted into the DB.

Thanks for the quick reply Dave 😊!

Collapse
Posted by Dave Bauer on
Hi,

I think _techincally_ you need to do the actual transformation in the ::tranform procedure.

The transform is used to take the user's entered data and convert it to the format used to store and process.

I'd have to go check the actual order tha the transform and validation occurs. Obviously if transform occurs before validation, the validation can stay the same, and you should do the conversion in the transform procedure instead.