Commit 38805d9d authored by Carsten  Rose's avatar Carsten Rose
Browse files

New FE.parameter 'inputType'. Can optional be given by webmaster. Additional,...

New FE.parameter 'inputType'. Can optional be given by webmaster. Additional, the 'type="number"' will be automatically set, if the column is of type 'int' or if 'min' and 'max' is numerically.
parent fa48da08
......@@ -2791,6 +2791,8 @@ Type: text
* *hideZero* = 0|1 (optional): `with hideZero=1` a '0' in the value will be replaced by an empty string.
* *emptyMeansNull* = [0|1] (optional): with `emptyMeansNull` or `emptyMeansNull=1` a NULL value will be written if
the value is an empty string
* *inputType* = number (optional). Typically the HTML tag 'type' will be 'text', 'textarea' or 'number' (detected automatically).
If necessary, the HTML tag 'type' might be forced to a specific given value.
.. _`input-typeahead`:
......
......@@ -1050,7 +1050,10 @@ abstract class AbstractBuildForm {
$typeAheadUrlParam = $this->typeAheadBuildParam($formElement);
if ($typeAheadUrlParam != '') {
$formElement[FE_TYPE] = FE_TYPE_SEARCH; // typeahead behaves better with 'search' instead of 'text'
if (empty($formElement[FE_INPUT_TYPE])) {
$formElement[FE_INPUT_TYPE] = FE_TYPE_SEARCH; // typeahead behaves better with 'search' instead of 'text'
}
if (empty($formElement[FE_INPUT_AUTOCOMPLETE])) {
$formElement[FE_INPUT_AUTOCOMPLETE] = 'off'; // typeahead behaves better with 'autocomplete'='off'
}
......@@ -1115,6 +1118,13 @@ abstract class AbstractBuildForm {
$value = number_format($value, $decimalScale, '.', '');
}
// In case the user specifies MIN & MAX with numbers, the html tag 'type' has to be 'number', to make the range check work in the browser.
if (empty($formElement[FE_INPUT_TYPE]) && !empty($formElement[FE_MIN]) && !empty($formElement[FE_MAX]) &&
is_numeric($formElement[FE_MIN]) && is_numeric($formElement[FE_MAX])
) {
$formElement[FE_INPUT_TYPE] = 'number';
}
$formElement = HelperFormElement::prepareExtraButton($formElement, !$flagTextarea);
if ($flagTextarea) {
$htmlTag = '<textarea';
......@@ -1124,7 +1134,10 @@ abstract class AbstractBuildForm {
$textarea = htmlentities($value) . '</textarea>';
} else {
$htmlTag = '<input';
$attribute .= $this->getAttributeList($formElement, ['type', 'size']);
if (!empty($formElement[FE_INPUT_TYPE])) {
$formElement[FE_TYPE] = $formElement[FE_INPUT_TYPE];
}
$attribute .= $this->getAttributeList($formElement, [FE_TYPE, 'size']);
$attribute .= Support::doAttribute('value', htmlentities($value), false);
}
......@@ -1263,7 +1276,7 @@ abstract class AbstractBuildForm {
private function adjustMaxLength(array &$formElement) {
// MIN( $formElement['maxLength'], tabledefinition)
$maxLength = $this->getColumnSize($formElement[FE_NAME]);
$maxLength = $this->getColumnSize($formElement);
$feMaxLength = false;
switch ($formElement[FE_TYPE]) {
......@@ -1303,12 +1316,14 @@ abstract class AbstractBuildForm {
/**
* Get column spec from tabledefinition and parse size of it. If nothing defined, return false.
*
* @param string $column
*
* @return bool|int a) 'false' if there is no length definition, b) length definition, c)
* @param $formElement
* @return bool|int a) 'false' if there is no length definition, b) length definition, c)
* date|time|datetime|timestamp use hardcoded length
*
*/
private function getColumnSize($column) {
private function getColumnSize(array &$formElement) {
$column = $formElement[FE_NAME];
$matches = array();
$typeSpec = $this->store->getVar($column, STORE_TABLE_COLUMN_TYPES);
......@@ -1327,6 +1342,76 @@ abstract class AbstractBuildForm {
break;
}
// $typeSpec = 'tinyint(3) UNSIGNED NOT NULL' | 'int(11) NOT NULL'
$arr = explode(' ', $typeSpec, 2);
if (empty($arr[1])) {
$sign = 'signed';
} else {
$arr = explode(' ', $arr[1], 2);
$sign = $arr[0] == 'unsigned' ? 'unsigned' : 'signed';
}
$arr = explode('(', $typeSpec, 2);
$token = $arr[0];
# s: signed, u: unsigned.
# s-min, s-max, s-checktype, u-min, u-max, u-checktype
$control = [
'tinyint' => [-128, 127, SANITIZE_ALLOW_NUMERICAL, 0, 255, SANITIZE_ALLOW_DIGIT],
'smallint' => [-32768, 32767, SANITIZE_ALLOW_NUMERICAL, 0, 65535, SANITIZE_ALLOW_DIGIT],
'mediumint' => [-8388608, 8388607, SANITIZE_ALLOW_NUMERICAL, 0, 16777215, SANITIZE_ALLOW_DIGIT],
'int' => [0, 4294967295, SANITIZE_ALLOW_NUMERICAL, -2147483648, 2147483647, SANITIZE_ALLOW_DIGIT],
'bigint' => [-9223372036854775808, 9223372036854775807, SANITIZE_ALLOW_NUMERICAL, 0, 18446744073709551615, SANITIZE_ALLOW_DIGIT],
];
$min = false;
$max = false;
$checkType = false;
switch ($token) {
case 'tinyint':
case 'smallint':
case 'mediumint':
case 'int':
case 'bigint':
$arr = $control[$token];
if ($sign == 'signed') {
$min = $arr[0];
$max = $arr[1];
$checkType = $arr[2];
} else {
$min = $arr[3];
$max = $arr[4];
$checkType = $arr[5];
}
break;
case 'decimal':
case 'float':
case 'double':
$checkType = SANITIZE_ALLOW_NUMERICAL;
break;
case 'bit':
$checkType = SANITIZE_ALLOW_DIGIT;
break;
}
if ($min !== false && $formElement[FE_MIN] == '') {
$formElement[FE_MIN] = $min;
}
if ($max !== false && $formElement[FE_MAX] == '') {
$formElement[FE_MAX] = $max;
}
// if given, force Checktype
if ($checkType !== false) {
$formElement[FE_CHECK_TYPE] = $checkType;
if (empty($formElement[FE_INPUT_TYPE])) {
$formElement[FE_INPUT_TYPE] = 'number';
}
}
// e.g.: string(64) >> 64, enum('yes','no') >> false
if (1 === preg_match('/\((.+)\)/', $typeSpec, $matches)) {
if (is_numeric($matches[1]))
......
......@@ -957,6 +957,7 @@ const FE_EMPTY_ITEM_AT_END = 'emptyItemAtEnd';
const FE_SUBRECORD_TABLE_CLASS = 'subrecordTableClass';
const FE_FILE_BUTTON_TEXT = 'fileButtonText';
const FE_FILE_BUTTON_TEXT_DEFAULT = 'Choose File';
const FE_INPUT_TYPE = 'inputType';
const FE_IMAGE_CUT_RESIZE_WIDTH = 'resizeWidth';
const FE_IMAGE_CUT_KEEP_ORIGINAL = 'keepOriginal';
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment