Hello!
Another problem i found when upgrading from kirby v2 to kirby v3… It was possible to save prices by a number field with step: .01, such as 15.00 (€). In Kirby v3, the “.00” gets removed now. Of course, I could add the zeros programmatically, but it would be way cleaner to just let me prevent this behaviour. Any ideas?
1 Like
there seem to be some tests in place but not for keeping zeros after the decimal dot (.00
).
$this->assertEquals('number', $field->type());
$this->assertEquals('number', $field->name());
$this->assertEquals(null, $field->value());
$this->assertEquals(null, $field->default());
$this->assertEquals(0, $field->min());
$this->assertEquals(null, $field->max());
$this->assertEquals(1, $field->step());
$this->assertTrue($field->save());
}
public function valueProvider()
{
return [
[null, null],
[false, (float)0],
[0, (float)0],
['0', (float)0],
[1, (float)1],
['1', (float)1],
['one', (float)0],
['1.1', (float)1.1],
the number field calls toNumber
* Allowed incremental steps between numbers (i.e 0.5)
*/
'step' => function ($step = 1) {
return $this->toNumber($step);
},
'value' => function ($value = null) {
return $this->toNumber($value);
}
],
'methods' => [
'toNumber' => function ($value) {
if ($this->isEmpty($value) === true) {
return null;
}
return (float)Str::float($value);
}
],
'validations' => [
'min',
'max'
which calls Str::float()
return static::substr($string, 0, strrpos(static::substr($string, 0, $chars), ' ')) . ' ' . $rep;
}
/**
* Convert the value to a float with a decimal
* point, no matter what the locale setting is
*
* @param string|int|float $value
* @return string
*/
public static function float($value): string
{
$value = str_replace(',', '.', $value);
$decimal = strlen(substr(strrchr($value, '.'), 1));
return number_format((float)$value, $decimal, '.', false);
}
/**
* Returns the rest of the string starting from the given character
*
* @param string $string
maybe vues js Number
type strips the trailing zeros?
disabled: Boolean,
id: [Number, String],
max: Number,
min: Number,
name: [Number, String],
placeholder: String,
preselect: Boolean,
required: Boolean,
step: Number,
value: {
type: [Number, String],
default: null
}
},
data() {
return {
listeners: {
...this.$listeners,
input: (event) => this.onInput(event.target.value)
}
}
@bnomei Yep, too bad tests only test what you want them to test. They could really be more intelligent
texnixe
November 8, 2019, 11:59am
5
This should be fixed in 3.3.0.
1 Like
Nope, sorry but i can still reproduce this bug with 3.3.0. It does not save neither 15,00 or 15.00, but always cuts it to 15
Looking at the merged pull request it seems like they fixed something in the .vue, when leaving directly the field, but it’s not about the frontend, it’s about what’s saved in the .txt file…
texnixe
November 17, 2019, 11:29pm
8
With the step option set? For me it works with the step option set, but I think there should be an error indicator if you enter a decimal where it is not intended.
opened 04:05PM - 14 Nov 19 UTC
Describe the bug
If you enter a decimal value into a number field that has no decimals defined, as soon as the...
Maybe we are talking about two different things here or I got something wrong - I’ve made a video to show you what behaviour i experience which I want to avoid: https://youtu.be/GgKWI1qDvPY
texnixe
November 18, 2019, 8:34pm
10
Ah, thank you, I somehow missed what you meant.
But see this issue comment:
It should not matter how it is stored in the content file though. If the frontend needs it displayed with a certain number of decimals, then this should be ensured by frontend code. ([Panel] Number field removes decimal values when they are 0. · Issue #1748 · getkirby/kirby · GitHub )
As far as I can see, all fixes were just related to the Vue component.