Commit 25263a36 authored by Carsten  Rose's avatar Carsten Rose
Browse files

Fixes #7682. 'Input textarea auto height'

parent 17f34a2e
Pipeline #2307 passed with stages
in 2 minutes and 40 seconds
......@@ -2866,8 +2866,9 @@ Fields:
+---------------------+-----------------------------+-----------------------------------------------------------------------------------------------------+
|labelAlign | left | Label align (default/left/center/right)/ Default: 'default' (defined by Form). |
+---------------------+-----------------------------+-----------------------------------------------------------------------------------------------------+
|Size | string | Visible length of input element. Might be omitted, depending on the chosen form layout. |
| | | Format: <width>,<height> (in characters) _`field-size` |
|Size | string | Depends on the FormElement type. E.g. visible length (and height) of input element `input-text`_ . |
| | | Might be omitted, depending on the chosen form layout. |
| | | Format: <width>[,<(min) height>[,<max height]] (in characters) _`field-size`. |
+---------------------+-----------------------------+-----------------------------------------------------------------------------------------------------+
|BS Label Columns | string | Number of bootstrap grid columns. By default empty, value inherits from the form. |
| | | _`field-bsLabelColumns`. See `bs-custom-field-width`_ |
......@@ -3263,10 +3264,20 @@ Type: text
^^^^^^^^^^
* General input for text and number.
* *FormElement.size* =
* *FormElement.size* = [<width>[,<min height>[,<max height>]]]
* <width>:
* Counted as character.
* If only the width is given, the height becomes automatically '1'.
* In general, the width of an input element is defined by the Bootstrap column width. The value here only has an
impact on calculating the final height in the '<width>,<min height>,<max height>' mode.
* <width>,<min height>: with a <min height> > 1 the input element is of type 'textarea', width=<width>, height=<min height>
* <width>,<min height>,<max height>: input element = textarea, width=<width>, height=`counting lines of current value`.
If a line is longer than '<width>', the line counts as `length(<line>) / <width> + 1` lines. The width is never less than
<min width> or greater than <max width>.
* <number>: width of input element in characters. Lineheight = 1.
* <cols>,<rows>: input element = textarea, width=<cols>, height=<rows>
* *FormElement.parameter*:
......
......@@ -1266,8 +1266,8 @@ abstract class AbstractBuildForm {
}
// Check for input type 'textarea'.
$colsRows = explode(',', $formElement[FE_SIZE], 2);
$flagTextarea = (count($colsRows) === 2);
$colsRows = explode(',', $formElement[FE_SIZE], 3);
$flagTextarea = (count($colsRows) > 1);
if ($formElement[FE_HIDE_ZERO] != '0' && $value == '0') {
$value = '';
......@@ -1292,6 +1292,11 @@ abstract class AbstractBuildForm {
if ($flagTextarea) {
$htmlTag = '<textarea';
// AutoHeight?
if (!empty($colsRows[2])) {
$colsRows[1] = HelperFormElement::textareaAutoHeight($colsRows, $value);
}
$attribute .= Support::doAttribute('cols', $colsRows[0]);
$attribute .= Support::doAttribute('rows', $colsRows[1]);
$textarea = htmlentities($value) . '</textarea>';
......
......@@ -526,4 +526,45 @@ EOF;
public static function booleParameter($data) {
return $data == '' || $data == '1';
}
/**
* Calculates (estimate) number of rows needed for a pre filled textarea element.
* Explode $value into lines. Check each line for number of textarea width rows. Count all and return this number.
* Apply min & max settings.
*
* @param array $colsRows
* @param string $value
* @return int
*/
public static function textareaAutoHeight(array $colsRows, $value) {
$cnt = 0;
// Check
if (count($colsRows) < 3) {
return ($colsRows[1] ?? 0);
}
if (empty($colsRows[0])) {
$colsRows[0] = 80; // just a default if no number is given.
}
// Explode into lines
$lines = explode(PHP_EOL, $value);
foreach ($lines as $line) {
$cnt += floor(strlen($line) / $colsRows[0]) + 1;
}
// Respect min/max.
if ($cnt < $colsRows[1]) {
$cnt = $colsRows[1];
}
if ($colsRows[2] < $cnt) {
$cnt = $colsRows[2];
}
return $cnt;
}
}
\ No newline at end of file
......@@ -203,22 +203,22 @@ VALUES
(1, 'title', 'Title', 'show', 'text', 'all', 'native', 120, 0, 0,
'<a tabindex="-1" href="{{documentation:Y}}#form-title">Info</a>',
'', '', '', '', 1, '', '', '', 'none', 'no', ''),
(1, 'noteInternal', 'Note', 'show', 'text', 'all', 'native', 130, '40,3', 0,
(1, 'noteInternal', 'Note', 'show', 'text', 'all', 'native', 130, '80,2,15', 0,
'<a tabindex="-1" href="{{documentation:Y}}#form-note">Info</a>', '', '', '', '', 1, '', '', '', 'specialchar', 'no',
''),
(1, 'tableName', 'Table', 'required', 'select', 'all', 'native', 140, 0, 0,
'<a tabindex="-1" href="{{documentation:Y}}#form-tablename">Info</a>', '', '', '{{[{{indexData:Y}}]!SHOW tables}}',
'emptyItemAtStart', 1, '', '', '', 'specialchar', 'no', ''),
(1, 'parameterLanguageA', 'Language: {{formLanguageALabel:YE}}', 'show', 'text', 'all', 'native', 150, '60,2', 0,
(1, 'parameterLanguageA', 'Language: {{formLanguageALabel:YE}}', 'show', 'text', 'all', 'native', 150, '80,2,15', 0,
'<a tabindex="-1" href="{{documentation:Y}}#multi-language-form">Info</a>', '', '', '', '', 1, '',
'{{SELECT IF("{{formLanguageAId:YE}}"="","hidden","show" ) }}', '', 'none', 'no', ''),
(1, 'parameterLanguageB', 'Language: {{formLanguageBLabel:YE}}', 'show', 'text', 'all', 'native', 160, '60,2', 0,
(1, 'parameterLanguageB', 'Language: {{formLanguageBLabel:YE}}', 'show', 'text', 'all', 'native', 160, '80,2,15', 0,
'<a tabindex="-1" href="{{documentation:Y}}#multi-language-form">Info</a>', '', '', '', '', 1, '',
'{{SELECT IF("{{formLanguageBId:YE}}"="","hidden","show" ) }}', '', 'none', 'no', ''),
(1, 'parameterLanguageC', 'Language: {{formLanguageCLabel:YE}}', 'show', 'text', 'all', 'native', 170, '60,2', 0,
(1, 'parameterLanguageC', 'Language: {{formLanguageCLabel:YE}}', 'show', 'text', 'all', 'native', 170, '80,2,15', 0,
'<a tabindex="-1" href="{{documentation:Y}}#multi-language-form">Info</a>', '', '', '', '', 1, '',
'{{SELECT IF("{{formLanguageCId:YE}}"="","hidden","show" ) }}', '', 'none', 'no', ''),
(1, 'parameterLanguageD', 'Language: {{formLanguageDLabel:YE}}', 'show', 'text', 'all', 'native', 180, '60,2', 0,
(1, 'parameterLanguageD', 'Language: {{formLanguageDLabel:YE}}', 'show', 'text', 'all', 'native', 180, '80,2,15', 0,
'<a tabindex="-1" href="{{documentation:Y}}#multi-language-form">Info</a>', '', '', '', '', 1, '',
'{{SELECT IF("{{formLanguageDId:YE}}"="","hidden","show" ) }}', '', 'none', 'no', ''),
......@@ -238,7 +238,7 @@ VALUES
(1, 'labelAlign', 'Label Align', 'show', 'radio', 'alnumx', 'native', 225, 0, 5,
'<a tabindex="-1" href="{{documentation:Y}}#definition">Info</a>', '', '', '', 'buttonClass', 3, '',
'', '', 'specialchar', 'no', ''),
(1, 'parameter', 'Parameter', 'show', 'text', 'all', 'native', 230, '40,8', 0,
(1, 'parameter', 'Parameter', 'show', 'text', 'all', 'native', 230, '80,2,15', 0,
'<a tabindex="-1" href="{{documentation:Y}}#form-parameter">Info</a>', '', '', '', '', 3, '', '', '', 'none', 'no',
''),
(1, 'bsLabelColumns', 'BS Label Columns', 'show', 'text', 'all', 'native', 240, 0, 0,
......@@ -301,7 +301,7 @@ VALUES
'specialchar', 'no', ''),
(1, 'multiMode', 'Multi Mode', 'show', 'radio', 'all', 'native', 520, 0, 0, '', '', '', '', '', 5, '', '', '',
'specialchar', 'no', ''),
(1, 'multiSql', 'Multi SQL', 'show', 'text', 'all', 'native', 530, '40,3', 0, '', '', '', '', '', 5, '', '', '',
(1, 'multiSql', 'Multi SQL', 'show', 'text', 'all', 'native', 530, '80,2,15', 0, '', '', '', '', '', 5, '', '', '',
'none', 'no', ''),
(1, 'multiDetailForm', 'Multi Detail Form', 'show', 'text', 'all', 'native', 540, 0, 0, '', '', '', '', '', 5,
'', '', '', 'specialchar', 'no', ''),
......@@ -378,19 +378,23 @@ VALUES (2, 'feIdContainer', 'Container', 'show', 'select', 'all', 'native', 120,
'', 100, '', 'yes', '', '', '',
'{{ SELECT IF("{{type:FRE:alnumx}}"="subrecord" AND "{{class:FRE:alnumx}}"="native", "show", "hidden") }}', '',
'specialchar'),
(2, 'parameterLanguageA', 'Language: {{formLanguageALabel:YE}}', 'show', 'text', 'all', 'native', 210, '60,2', 0,
(2, 'parameterLanguageA', 'Language: {{formLanguageALabel:YE}}', 'show', 'text', 'all', 'native', 210, '80,2,15',
0,
'<a tabindex="-1" href="{{documentation:Y}}#multi-language-form">Info</a>', '', '', '', '', 100, '', 'no', '',
'', '',
'{{SELECT IF("{{formLanguageAId:YE}}"="","hidden","show" ) }}', '', 'none'),
(2, 'parameterLanguageB', 'Language: {{formLanguageBLabel:YE}}', 'show', 'text', 'all', 'native', 210, '60,2', 0,
(2, 'parameterLanguageB', 'Language: {{formLanguageBLabel:YE}}', 'show', 'text', 'all', 'native', 210, '80,2,15',
0,
'<a tabindex="-1" href="{{documentation:Y}}#multi-language-form">Info</a>', '', '', '', '', 100, '', 'no', '',
'', '',
'{{SELECT IF("{{formLanguageBId:YE}}"="","hidden","show" ) }}', '', 'none'),
(2, 'parameterLanguageC', 'Language: {{formLanguageCLabel:YE}}', 'show', 'text', 'all', 'native', 210, '60,2', 0,
(2, 'parameterLanguageC', 'Language: {{formLanguageCLabel:YE}}', 'show', 'text', 'all', 'native', 210, '80,2,15',
0,
'<a tabindex="-1" href="{{documentation:Y}}#multi-language-form">Info</a>', '', '', '', '', 100, '', 'no', '',
'', '',
'{{SELECT IF("{{formLanguageCId:YE}}"="","hidden","show" ) }}', '', 'none'),
(2, 'parameterLanguageD', 'Language: {{formLanguageDLabel:YE}}', 'show', 'text', 'all', 'native', 210, '60,2', 0,
(2, 'parameterLanguageD', 'Language: {{formLanguageDLabel:YE}}', 'show', 'text', 'all', 'native', 210, '80,2,15',
0,
'<a tabindex="-1" href="{{documentation:Y}}#multi-language-form">Info</a>', '', '', '', '', 100, '', 'no', '',
'', '',
'{{SELECT IF("{{formLanguageDId:YE}}"="","hidden","show" ) }}', '', 'none'),
......@@ -421,7 +425,8 @@ VALUES (2, 'feIdContainer', 'Container', 'show', 'select', 'all', 'native', 120,
'<a tabindex="-1" href="{{documentation:Y}}#field-tabindex">Info</a>', '', '', '', '', 101, '', 'no', '', '',
'', '', '',
'specialchar'),
(2, 'adminNote', 'Internal Note', 'show', 'text', 'all', 'native', 360, '60,4', 0, '', '', '', '', '', 101, '',
(2, 'adminNote', 'Internal Note', 'show', 'text', 'all', 'native', 360, '80,2,15', 0, '', '', '', '', '', 101,
'',
'no',
'', '',
'', '', '', 'specialchar'),
......@@ -458,7 +463,7 @@ VALUES (2, 'feIdContainer', 'Container', 'show', 'select', 'all', 'native', 120,
'<a tabindex="-1" href="{{documentation:Y}}#field-maxlength">Info</a>', '', '', '', '', 102, '', 'no', '', '',
'', '', '',
'specialchar'),
(2, 'note', 'Note', 'show', 'text', 'all', 'native', 460, '40,5', 0,
(2, 'note', 'Note', 'show', 'text', 'all', 'native', 460, '80,2,15', 0,
'<a tabindex="-1" href="{{documentation:Y}}#field-note">Info</a>', '', '', '', '', 102, '', 'no', '', '', '',
'', '', 'none'),
(2, 'tooltip', 'Tooltip', 'show', 'text', 'all', 'native', 470, 0, 0,
......@@ -470,14 +475,14 @@ VALUES (2, 'feIdContainer', 'Container', 'show', 'select', 'all', 'native', 120,
'', '', '',
'none'),
(2, 'value', 'value', 'show', 'text', 'all', 'native', 500, '40,2', 0,
(2, 'value', 'value', 'show', 'text', 'all', 'native', 500, '80,2,15', 0,
'<a tabindex="-1" href="{{documentation:Y}}#field-value">Info</a>', '', '', '', '', 103, '', 'no', '', '', '',
'', '',
'none'),
(2, 'sql1', 'sql1', 'show', 'text', 'all', 'native', 510, '40,5', 0,
(2, 'sql1', 'sql1', 'show', 'text', 'all', 'native', 510, '80,2,15', 0,
'<a tabindex="-1" href="{{documentation:Y}}#sql1">Info</a><br><br>MariaDB: <a tabindex="-1" href="https://mariadb.com/kb/en/mariadb/select/">Select</a>, <a tabindex="-1" href="https://mariadb.com/kb/en/mariadb/functions-and-operators/">Functions</a>',
'', '', '', '', 103, '', 'no', '', '', '', '', '', 'none'),
(2, 'parameter', 'Parameter', 'show', 'text', 'all', 'native', 520, '40,8', 0,
(2, 'parameter', 'Parameter', 'show', 'text', 'all', 'native', 520, '80,2,15', 0,
'<a tabindex="-1" href="{{documentation:Y}}#fe-parameter-attributes">Info</a>',
'', '', '', '', 103, '', 'no', '', '', '', '', '', 'none');
......@@ -633,10 +638,10 @@ VALUES (4, 'status', 'Enabled', 'show', '', 'checkbox', 'specialchar', 'alnumx',
(4, 'sql1', 'Mail', 'show', '{{SELECT IF("{{type:FR:alnumx}}"="mail","show","hidden") }}', 'text', 'none', 'all',
60,
'extraButtonInfo = Query: &#123;&#123;!SELECT ... as sendMailTo...&#125;&#125;<br><b>sendMailTo / sendMailCc / sendMailBcc</b>: Separate multiple by comma.<br><b>sendMailFrom</b><br><b>sendMailSubject</b><br><b>sendMailReplyTo</b>: Optional<br><b>sendMailFlagAutoSubmit</b>: Optional. on|off. Default on - if "on", suppresses OoO answers from receivers.<br><b>sendMailGrId</b>: Optional<br><b>sendMailXId</b>: Optional',
'60,4', '', 'yes', '', '', ''),
'80,2,15', '', 'yes', '', '', ''),
(4, 'content', '{{SELECT IF("{{type:FR:alnumx}}"="mail","Mail body","URL") }}', 'show', '', 'text', 'none',
'all', 70,
'', '40,4',
'', '80,2,15',
'Website: URL absolute like "http://..." or relative like "?id=pagealias..."<br>Mail: Static Body or &#123;{SELECT ...&#125;}',
'yes', '', '', ''),
......@@ -651,7 +656,8 @@ VALUES (4, 'status', 'Enabled', 'show', '', 'checkbox', 'specialchar', 'alnumx',
'yes', '', '', ''),
(4, 'lastRun', 'Last run', 'readonly', '', 'text', 'specialchar', 'alnumx', 120, '', '', '', 'no', '', '', ''),
(4, 'lastStatus', 'Laststatus', 'readonly', '', 'text', 'specialchar', 'alnumx', 130, '', '50,6', '', 'no', '3',
(4, 'lastStatus', 'Laststatus', 'readonly', '', 'text', 'specialchar', 'alnumx', 130, '', '80,2,15', '', 'no',
'3',
'9',
'0'),
(4, 'inProgress', 'In progress since', 'show', '', 'text', 'specialchar', 'alnumx', 140,
......
......@@ -201,6 +201,33 @@ class HelperFormElementTest extends TestCase {
$this->assertEquals('{"red":18,"green":52,"blue":86}', $result, "Expect white");
}
public function testTextareaAutoHeight() {
$result = HelperFormElement::textareaAutoHeight([], '');
$this->assertEquals('0', $result);
$result = HelperFormElement::textareaAutoHeight([1], '');
$this->assertEquals('0', $result);
$result = HelperFormElement::textareaAutoHeight([1, 1], '');
$this->assertEquals('1', $result);
$result = HelperFormElement::textareaAutoHeight([1, 1, 1], '');
$this->assertEquals('1', $result);
$result = HelperFormElement::textareaAutoHeight([20, 1, 10], 'one line');
$this->assertEquals('1', $result);
$result = HelperFormElement::textareaAutoHeight([20, 1, 10], "Expect white\nExpect white\nExpect white");
$this->assertEquals('3', $result);
$result = HelperFormElement::textareaAutoHeight([20, 1, 2], "Expect white\nExpect white\nExpect white");
$this->assertEquals('2', $result);
$result = HelperFormElement::textareaAutoHeight([20, 1, 10], "Expect white\nExpect white Expect white Expect white\nExpect white");
$this->assertEquals('4', $result);
}
/**
* @expectedException \UserFormException
*
......@@ -223,6 +250,8 @@ class HelperFormElementTest extends TestCase {
}
// public function testExplodeTemplateGroupElements() {
// $formElements = array();
//
......
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