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.
if ($this->getPropertyValue('min_max_type') == 'value') {
    $attribs['min'] = strlen($this->getPropertyValue('min_value'));
    $attribs['max'] = strlen($this->getPropertyValue('min_value')) - $attribs['min'];
}

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
bleenders
View Replies:
DeWebmakers replied on at Permalink Reply
DeWebmakers
Hi,

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

concrete5 Environment Information

# concrete5 Version
Core Version - 8.5.2
Version Installed - 8.5.2
Database Version - 20190925072210

# Database Information
Version: 10.1.44-MariaDB-0ubuntu0.18.04.1
SQL Mode: NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION

# concrete5 Packages
######, Formidable (Full Version) (2.1.3)

# concrete5 Overrides
None

# concrete5 Cache Settings
Block Cache - Off
Overrides Cache - Off
Full Page Caching - Off
Full Page Cache Lifetime - Every 6 hours (default setting).

# Server Software
Apache/2.4.29 (Ubuntu)

# Server API
fpm-fcgi

# PHP Version
7.3.21-1+ubuntu18.04.1+deb.sury.org+1

# PHP Extensions
bcmath, blackfire, calendar, cgi-fcgi, Core, ctype, curl, date, dom, exif, fileinfo, filter, ftp, gd, gettext, hash, iconv, imagick, intl, json, ldap, libxml, mbstring, mysqli, mysqlnd, openssl, pcre, PDO, pdo_mysql, pdo_sqlite, Phar, posix, readline, redis, Reflection, session, shmop, SimpleXML, soap, sockets, sodium, SPL, sqlite3, standard, sysvmsg, sysvsem, sysvshm, tokenizer, wddx, xdebug, xml, xmlreader, xmlwriter, xsl, Zend OPcache, zip, zlib

# PHP Settings
max_execution_time - 30
log_errors_max_len - 1024
max_file_uploads - 20
max_input_nesting_level - 64
max_input_time - 60
max_input_vars - 1000
memory_limit - 128M
post_max_size - 64M
upload_max_filesize - 32M
ldap.max_links - Unlimited
mbstring.regex_stack_limit - 100000
mysqli.max_links - Unlimited
mysqli.max_persistent - Unlimited
pcre.backtrack_limit - 1000000
pcre.recursion_limit - 100000
redis.pconnect.connection_limit - 0
session.cache_limiter - <i>no value</i>
session.gc_maxlifetime - 7200
soap.wsdl_cache_limit - 5
xdebug.max_nesting_level - 256
xdebug.max_stack_frames - -1
xdebug.var_display_max_children - 128
xdebug.var_display_max_data - 512
xdebug.var_display_max_depth - 3
opcache.max_accelerated_files - 10000
opcache.max_file_size - 0
opcache.max_wasted_percentage - 5

Browser User-Agent String

Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:79.0) Gecko/20100101 Firefox/79.0

Hide Post Content

This will replace the post content with the message: "Content has been removed by an Administrator"

Hide Content

Request Refund

You may not request a refund that is not currently owned by you.