From 8fa3bdb88e4c66ddbd9416077f30b6566913a019 Mon Sep 17 00:00:00 2001 From: Ralf Becker Date: Wed, 31 Oct 2012 09:20:24 +0000 Subject: [PATCH] * eTemplate/all apps: fixed not working display of floating point values in input fields for Chrome or Safarie (browsers supporting html5 input type="number") --- etemplate/inc/class.etemplate.inc.php | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/etemplate/inc/class.etemplate.inc.php b/etemplate/inc/class.etemplate.inc.php index 405d7952ee..316c572877 100644 --- a/etemplate/inc/class.etemplate.inc.php +++ b/etemplate/inc/class.etemplate.inc.php @@ -1879,6 +1879,11 @@ class etemplate extends boetemplate /** * Format a number according to user prefs with decimal and thousands separator (later only for readonly) * + * HTML5 input type=number requires a float value with a dot, not comma! + * Chrome 22 and Safari 6 shows no value if a comma is used, + * while FF 16, IE 9 and 10 have no support for input type=number :-( + * --> use . as decimal separator for browser supporting html5 input type=number + * * @param int|float|string $number * @param int $num_decimal_places=2 * @param boolean $readonly=true @@ -1895,7 +1900,13 @@ class etemplate extends boetemplate } if ((string)$number === '') return ''; - return number_format(str_replace(' ','',$number),$num_decimal_places,$dec_separator,$readonly ? $thousands_separator : ''); + $ret = number_format(str_replace(' ','',$number), $num_decimal_places, + // need to use '.' as decimal separator for all browser supporting html5 input type=number + $dec_sep_used=$readonly || !in_array(html::$user_agent, array('chrome', 'safari', 'opera')) ? + $dec_separator : '.', + $readonly ? $thousands_separator : ''); + //error_log(__METHOD__."($number, $num_decimal_places, $readonly) html::user_agent=".html::$user_agent.", dec_sep='$dec_separator' --> '$dec_sep_used', thousands_sep='$thousands_separator' returning '$ret'"); + return $ret; } /**