1
0
mirror of https://github.com/processwire/processwire.git synced 2025-08-10 16:54:44 +02:00
This commit is contained in:
Ryan Cramer
2022-07-08 12:09:18 -04:00
parent 2e76df1a89
commit 5d9ee59036

View File

@@ -72,16 +72,26 @@ class InputfieldFloat extends InputfieldInteger {
*
*/
protected function sanitizeValue($value) {
if(!strlen("$value")) return '';
if($this->digits > 0) {
return is_numeric("$value") ? (string) $value : '';
if(!strlen("$value")) {
$value = '';
} else if($this->digits > 0) {
$value = (string) $value;
if(!is_numeric("$value")) {
$value = $this->wire()->sanitizer->float($value, array(
'precision' => (int) $this->precision,
'getString' => 'F',
'blankValue' => '',
));
}
} else if(!is_float($value) && !is_int($value)) {
$value = $this->wire()->sanitizer->float($value, array('blankValue' => ''));
if(!strlen("$value")) return '';
if(!strlen("$value")) $value = '';
} else {
$precision = $this->precision;
if($precision === null || $precision === '') $precision = $this->getPrecision($value);
$value = is_int($precision) && $precision > 0 ? round((float) $value, $precision) : $value;
}
$precision = $this->precision;
if($precision === null || $precision === '') $precision = $this->getPrecision($value);
return is_int($precision) && $precision > 0 ? round((float) $value, $precision) : $value;
return $value;
}
/**
@@ -138,6 +148,12 @@ class InputfieldFloat extends InputfieldInteger {
if($attributes && !empty($attributes['value']) && $this->noE && $this->hasE($attributes['value'])) {
$attributes['value'] = $this->wire()->sanitizer->float($attributes['value'], array('getString' => true));
}
if($attributes && $this->precision > 0 && $this->digits > 0) {
if(isset($attributes['value']) && strlen("$attributes[value]")) {
$f = $attributes['type'] === 'number' ? 'F' : 'f'; // F=non-locale aware, f=locale aware
$attributes['value'] = sprintf("%.{$this->precision}$f", (float) $attributes['value']);
}
}
return parent::getAttributesString($attributes);
}