Dear support team,
is it possible to to localize my controls? My goal is to use decimal number with decimal points (comma) and not with points!
Thank you
Alex
is it possible to to localize my controls? My goal is to use decimal number with decimal points (comma) and not with points!
Thank you
Alex
At the moment on entry decimal number for example 3,6 my db save it as 3.
The same thing is with validation. It works with dots only.
In this case I though that I can change the settings (localization) to germany to work with ",".
...why is it so complicated to work with chronoforms wizard🙂.
Alex
The same thing is with validation. It works with dots only.
In this case I though that I can change the settings (localization) to germany to work with ",".
...why is it so complicated to work with chronoforms wizard🙂.
Alex
Hi mergui,
I'm not sure if this helps but here's a code snippet to clean up a number and convert it to a 99999.99 format for saving in the database. You can use it in a Custom Code action or a Custom Serverside Validation action in the On Submit event.
Client-side validation is trickier, I think that the answer is to add a custom amount validator using code like this in a Load JS action:
To validate an amount input add class="validate['%checkAmount'] to the input.
Bob
I'm not sure if this helps but here's a code snippet to clean up a number and convert it to a 99999.99 format for saving in the database. You can use it in a Custom Code action or a Custom Serverside Validation action in the On Submit event.
<?php
$amount = $form->data[$amount_name];
$amount = preg_replace('#[^0-9,.]+#', '', $amount);
$dec = substr($amount, -3, 1);
if ( $dec == ',' || $dec == '.' ) {
$dec = 2;
} else {
$dec = 0;
}
$amount = preg_replace('#[^0-9]+#', '', $amount);
if ( $dec ) {
$amount = $amount/100;
}
if ( !$amount || $amount <= 0 ) {
$form->validation_errors['amount'] = JText::_( 'CF_AA_GH_ERROR_AMOUNT' );
$invalid_data = true;
}
$amount = number_format($amount, $dec, '.', '');
?>
Client-side validation is trickier, I think that the answer is to add a custom amount validator using code like this in a Load JS action:
function checkAmount(el){
if (!el.value.test(/^(?:^[+-]?[0-9]{1,3}(?:[0-9]*(?:[.,][0-9]{2})?|(?:,[0-9]{3})*(?:\.[0-9]{2})?|(?:\.[0-9]{3})*(?:,[0-9]{2})?)$)$/i)) {
el.errors.push("Please enter a valid amount");
return false;
} else {
return true;
}
};
The regex is from Regex Buddy and should validate "Number: Currency amount US & EU (cents optional). Can use US-style 123,456.78 notation and European-style 123.456,78 notation. Optional thousands separators; optional two-digit fraction"To validate an amount input add class="validate['%checkAmount'] to the input.
Bob
This topic is locked and no more replies can be posted.