Integer field is broken
Permalink Browser Info Environment
An old client pointed out that the integer field was not working.
So there is some faulty logic in the generateInput method of Concrete\Package\FormidableFull\Src\Formidable\Element\Integer
When the user wants to configure a min and max value on the field this will be applied.
Lets say the user gave in min 1 and max 10
min = 1 because the string length = 1 ???? Not because the integer is 1.
So if the user configures min 9, min is still 1? Why?
When min = 1 max is 1 (length of the string) minus 1 (the length of the string)?
So max is always 0??
Wouldn't it make more sense to do:
When the user wants to configure a min and max number of characters this will be applied.
Lets say the user gave in min 1 and max 10.
Min should be 0(or -9?), and max should be 9.999.999.999
But here min will be 1(intval 1)
Max will be at first 1 (intval 1). Why again the intval of the min_value???
But then max will be changed to 9 (1(intval min value) repetitions of 9)
Wouldn't it make more sense to do:
I expected to find support tickets around this problem, but there are none. Is no one using the field?
So there is some faulty logic in the generateInput method of Concrete\Package\FormidableFull\Src\Formidable\Element\Integer
When the user wants to configure a min and max value on the field this will be applied.
Lets say the user gave in min 1 and max 10
min = 1 because the string length = 1 ???? Not because the integer is 1.
So if the user configures min 9, min is still 1? Why?
When min = 1 max is 1 (length of the string) minus 1 (the length of the string)?
So max is always 0??
Wouldn't it make more sense to do:
$attribs['min'] = (int) $this->getPropertyValue('min_value'); $attribs['max'] = ((int) $this->getPropertyValue('max_value') > $attribs['min']) ? (int) $this->getPropertyValue('max_value') : $attribs['min'] + 1;
When the user wants to configure a min and max number of characters this will be applied.
elseif ($this->getPropertyValue('min_max_type') == 'chars') { $attribs['min'] = intval($this->getPropertyValue('min_value')); $attribs['max'] = intval($this->getPropertyValue('min_value')); if (!empty($attribs['max'])) $attribs['max'] = str_repeat('9', $attribs['max']); }
Lets say the user gave in min 1 and max 10.
Min should be 0(or -9?), and max should be 9.999.999.999
But here min will be 1(intval 1)
Max will be at first 1 (intval 1). Why again the intval of the min_value???
But then max will be changed to 9 (1(intval min value) repetitions of 9)
Wouldn't it make more sense to do:
$attribs['min'] = $attribs['min'] = (int) $this->getPropertyValue('min_value') === 1 ? 0 : (10 ** (int) $this->getPropertyValue('min_value')) - 1; $attribs['max'] = str_repeat('9', (int) $this->getPropertyValue('max_value')); $attribs['max'] = ($attribs['min'] < $attribs['max']) ? $attribs['max'] : str_repeat('9', strlen($attribs['min']));
I expected to find support tickets around this problem, but there are none. Is no one using the field?
Type: | Discussion |
---|---|
Status: | In Progress |
Just checked..
You are right. There is something weird happing there...
I will change this to the following:
If "value" is selected. The min and max-value will be as filled in.
When "chars" is selected the min value will be the min value with that char length. So if 1 is entered the min value will be 0. When 2 is entered it will be 10 and so on...
For the max it will be max value with that string length. So if 5 is entered, max value is 99999.
Thanks for helping!
I'll update the addon asap.
Best,
Corretje