name="mynumber" type="number" default="0" min="-123"
Correct behavior when using negative values
If the value is set to <= 0 the field value is set to its min-value.
Also the default value is ignored and the field's min-value is used instead.
Joomla 3.5, PHP 5.6
I did some research on the form field code and it seems that the "empty value detection" is not working as expected. Since empty(0) will return true, the specified min-value will always be used. This is okay as long as you use positive numbers, but fails with negative.
Here's a suggestion on fixing this (File: libraries/joomla/form/fields/number.php:160)
replace
$value = (float) $this->value; $value = empty($value) ? $this->min : $value;
with
// Make sure to set a valid default value (use min if 'default' not set or 0 if 'default' and 'min' not set) if($this->value === "") { if(isset($this->min)) { $value = (float) $this->min; } else { $value = 0; } } else { $value = (float) $this->value; }
Sorry, just edited my post
I think replace these two lines of code https://github.com/joomla/joomla-cms/blob/staging/libraries/joomla/form/fields/number.php#L160-L161 with this line should solve the issue:
$value = is_numeric($this->value) ? (float) $this->value : $this->min;
Yes, this fixes the issue.
But if optional "default" and "min" options are not set, $value will get null on an empty form.
Maybe it should be set to 0 to perfect this solution.
Something like this?
$this->min = isset($this->min) ? $this->min : 0;
$value = is_numeric($this->value) ? (float) $this->value : $this->min;
Status | New | ⇒ | Closed |
Closed_Date | 0000-00-00 00:00:00 | ⇒ | 2016-03-07 22:48:45 |
Closed_By | ⇒ | brianteeman |
You're minimum data seems to have got lost in the first point - could you edit it please :)