LSattr_html::valueWithUnit: fix handling zero value

This commit is contained in:
Benjamin Renard 2021-03-25 15:52:51 +01:00
parent dff2aa8b46
commit d637a570f1
2 changed files with 18 additions and 9 deletions

View file

@ -90,7 +90,16 @@ class LSformElement_valueWithUnit extends LSformElement {
if (!$details)
return $infos['value'];
$units = $this -> getUnits();
if ($units) {
if (!$units)
return $infos;
if ($infos['value'] == 0) {
ksort($units);
$infos['valueWithUnit'] = $this -> formatNumber(0);
$infos['unitSill'] = key($units);
$infos['unitLabel'] = $units[$infos['unitSill']];
return $infos;
}
foreach($units as $sill => $label) {
if ($infos['value'] >= $sill) {
$infos['valueWithUnit'] = $this -> formatNumber($infos['value']/$sill);
@ -99,7 +108,7 @@ class LSformElement_valueWithUnit extends LSformElement {
break;
}
}
}
return $infos;
}
return false;

View file

@ -13,7 +13,7 @@
{$noValueTxt|escape:"htmlall"}
{/if}
{else}
{if $values_and_units[$value].valueWithUnit || !$values_and_units[$value]}
{if isset($values_and_units[$value].valueWithUnit) || !$values_and_units[$value]}
<input name='{$attr_name|escape:"htmlall"}_valueWithUnit[]' type=text class='LSformElement_valueWithUnit' value='{$values_and_units[$value].valueWithUnit|escape:"htmlall"}'/>
<select name='{$attr_name|escape:"htmlall"}_unitFact[]' class='LSform LSformElement_valueWithUnit'>
{html_options options=$units selected=$values_and_units[$value].unitSill}