Commit 3792b029 authored by Carsten  Rose's avatar Carsten Rose
Browse files

Merge branch 'f9521TextArea' into 'master'

Refs #9521 Textarea: update Manual.rst. Update FormEditor to 80,1,350.

See merge request !198
parents 7ec04c58 cd1de1d2
Pipeline #2668 passed with stages
in 2 minutes and 51 seconds
......@@ -3321,28 +3321,34 @@ Type: extra
Type: text
^^^^^^^^^^
General input for text and number.
General input for any text.
.. _`field-size`:
* *FormElement.size* = [<width>[,<min height>[,<max height>]]]
* By default, the maximum length of input data is automatically restricted by the underlying database column.
* HTML decides between one line input (=Input text) and multiline input (=Textarea).
* *FormElement.size* = [<width>[,<min height (lines)>[,<max height (pixel)>]]]
* The 'size' parameter might have 0-3 parameter.
* If 0-2 parameter are given, the height is static.
* If 3 parameter are given, the `auto height` mode is activated and the height is dynamically calculated, with respect to
given min/max height.
* Width measured in characters, height measured in lines.
* If only the width is given, the height becomes automatically '1'.
* In general, the *visible* width of an input element is defined by the Bootstrap column width (and *not* the width given
here). The width value here only has an impact on calculating the final height in the `auto height` mode.
* The dynamic Bootstrap width of the shown textarea element makes it hard to calculate the real needed height. The
implementation is only a 'best guess'.
* `<width>,<min height>`: with a `<min height>` > 1 the form element is of type 'textarea' (else 'input').
* `<width>,<min height>,<max height>`: height=`counting lines of current value`.
If a line is longer than `<width>`, the height of the line counts as `length(<line>) / <width> + 1` lines. The height
is never less than `<min height>` or greater than `<max height>`.
* The parameter is optional and controls the behaviour of the input / textarea element.
* The `<width>` is counted in 'characters'.
* But: the *visible* width of an input element is defined by the Bootstrap column width (and *not* the width given
here). Finally: the value here is meaningless. Nevertheless it has to be given for future compatibility.
* `<min-height>`:
* Counted as 'lines'.
* If not set the height is treated as 1.
* A `<min-height>` of 1 forces an one line input. Exception: `<max-height>` > 0 enables `auto-grow`.
* `<max-height>`:
* Controls the `auto-grow`-Mode.
* Counted in 'pixel'.
* If not set it becomes the default of 350 pixels.
* If > 0, the `auto-grow` mode is activated and the height of the textarea will be dynamically updated
up to `<max-height>`.
* If = 0, the `auto-grow` mode is disabled.
* *FormElement.parameter*:
......@@ -3361,6 +3367,7 @@ General input for text and number.
If necessary, the HTML tag 'type' might be forced to a specific given value.
* *step* = Step size of the up/down buttons which increase/decrease the number of in the input field. Optional.
Default 1. Only useful with `inputType=number` (defined explicit via `inputType` or detected automatically).
* *textareaResize* = 0|1 (optional). Be default = 1 (=on). A textarea element is resizable by the user.
.. _`input-typeahead`:
......
......@@ -1446,10 +1446,8 @@ abstract class AbstractBuildForm {
if (empty($colsRows[1])) {
$colsRows[1] = 1;
}
$flagTextarea = ($colsRows[1] > 1);
// AutoHeight
// $colsRows[1] = HelperFormElement::textareaAutoHeight($colsRows, $value);
$flagTextarea = ($colsRows[1] > 1 || ($colsRows[2] ?? '') > 0);
$formElement = HelperFormElement::prepareExtraButton($formElement, !$flagTextarea);
......
......@@ -532,46 +532,4 @@ 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.
* If no <height> is given, return always 1 - easy way to detect single or multile line input/textarea.
*
* @param array $colsRows
* @param string $value
* @return int
*/
public static function textareaAutoHeight(array $colsRows, $value) {
$cnt = 0;
// Check
if (count($colsRows) < 3) {
return (empty($colsRows[1]) ? 1 : $colsRows[1]);
}
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
......@@ -200,25 +200,25 @@ VALUES
'<a tabindex="-1" href="{{documentation:Y}}#form-name">Info</a>', '', '', '',
'autofocus\ndata-pattern-error=Allowed characters: alphabet, number or . - +',
1, '', '', '', 'specialchar', 'no', '[a-zA-Z0-9._+-]+'),
(1, 'title', 'Title', 'show', 'text', 'all', 'native', 120, '80,2', 0,
(1, 'title', 'Title', 'show', 'text', 'all', 'native', 120, '80,1,350', 0,
'<a tabindex="-1" href="{{documentation:Y}}#form-title">Info</a>',
'', '', '', '', 1, '', '', '', 'none', 'no', ''),
(1, 'noteInternal', 'Note', 'show', 'text', 'all', 'native', 130, '80,2', 0,
(1, 'noteInternal', 'Note', 'show', 'text', 'all', 'native', 130, '80,1,350', 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, '80,2', 0,
(1, 'parameterLanguageA', 'Language: {{formLanguageALabel:YE}}', 'show', 'text', 'all', 'native', 150, '80,1,350', 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, '80,2', 0,
(1, 'parameterLanguageB', 'Language: {{formLanguageBLabel:YE}}', 'show', 'text', 'all', 'native', 160, '80,1,350', 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, '80,2', 0,
(1, 'parameterLanguageC', 'Language: {{formLanguageCLabel:YE}}', 'show', 'text', 'all', 'native', 170, '80,1,350', 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, '80,2', 0,
(1, 'parameterLanguageD', 'Language: {{formLanguageDLabel:YE}}', 'show', 'text', 'all', 'native', 180, '80,1,350', 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, '80,2', 0,
(1, 'parameter', 'Parameter', 'show', 'text', 'all', 'native', 230, '80,1,350', 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,
......@@ -302,7 +302,7 @@ VALUES
(1, 'multiMode', 'Multi Mode', 'show', 'radio', 'all', 'native', 520, 0, 0, '', '', '', '', 'buttonClass', 5, '', '',
'',
'specialchar', 'no', ''),
(1, 'multiSql', 'Multi SQL', 'show', 'text', 'all', 'native', 530, '80,2', 0, '', '', '', '', '', 5, '', '', '',
(1, 'multiSql', 'Multi SQL', 'show', 'text', 'all', 'native', 530, '80,1,350', 0, '', '', '', '', '', 5, '', '', '',
'none', 'no', ''),
(1, 'multiDetailForm', 'Multi Detail Form', 'show', 'text', 'all', 'native', 540, 0, 0, '', '', '', '', '', 5,
'', '', '', 'specialchar', 'no', ''),
......@@ -359,7 +359,7 @@ VALUES (2, 'feIdContainer', 'Container', 'show', 'select', 'all', 'native', 120,
(2, 'mode', 'Mode', 'show', 'radio', 'all', 'native', 160, 0, 0,
'<a tabindex="-1" href="{{documentation:Y}}#class-native">Info</a>',
'', '', '', 'buttonClass=btn-default', 100, '', 'no', '', '', '', '', '', 'specialchar'),
(2, 'modeSql', 'Mode sql', 'show', 'text', 'all', 'native', 170, '70,2', 0,
(2, 'modeSql', 'Mode sql', 'show', 'text', 'all', 'native', 170, '80,1,350', 0,
'<a tabindex="-1" href="{{documentation:Y}}#dynamic-update">Info</a>', '', '', '', '', 100, '', 'no', '', '',
'', '', '',
'none'),
......@@ -380,22 +380,26 @@ 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, '80,2',
(2, 'parameterLanguageA', 'Language: {{formLanguageALabel:YE}}', 'show', 'text', 'all', 'native', 210,
'80,1,350',
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, '80,2',
(2, 'parameterLanguageB', 'Language: {{formLanguageBLabel:YE}}', 'show', 'text', 'all', 'native', 210,
'80,1,350',
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, '80,2',
(2, 'parameterLanguageC', 'Language: {{formLanguageCLabel:YE}}', 'show', 'text', 'all', 'native', 210,
'80,1,350',
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, '80,2',
(2, 'parameterLanguageD', 'Language: {{formLanguageDLabel:YE}}', 'show', 'text', 'all', 'native', 210,
'80,1,350',
0,
'<a tabindex="-1" href="{{documentation:Y}}#multi-language-form">Info</a>', '', '', '', '', 100, '', 'no', '',
'', '',
......@@ -427,7 +431,7 @@ 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, '80,2', 0, '', '', '', '', '', 101,
(2, 'adminNote', 'Internal Note', 'show', 'text', 'all', 'native', 360, '80,1,350', 0, '', '', '', '', '', 101,
'',
'no',
'', '',
......@@ -465,7 +469,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, '80,2', 0,
(2, 'note', 'Note', 'show', 'text', 'all', 'native', 460, '80,1,350', 0,
'<a tabindex="-1" href="{{documentation:Y}}#field-note">Info</a>', '', '', '', '', 102, '', 'no', '', '', '',
'', '', 'none'),
(2, 'tooltip', 'Tooltip', 'show', 'text', 'all', 'native', 470, 0, 0,
......@@ -477,14 +481,14 @@ VALUES (2, 'feIdContainer', 'Container', 'show', 'select', 'all', 'native', 120,
'', '', '',
'none'),
(2, 'value', 'value', 'show', 'text', 'all', 'native', 500, '80,2', 0,
(2, 'value', 'value', 'show', 'text', 'all', 'native', 500, '80,1,350', 0,
'<a tabindex="-1" href="{{documentation:Y}}#field-value">Info</a>', '', '', '', '', 103, '', 'no', '', '', '',
'', '',
'none'),
(2, 'sql1', 'sql1', 'show', 'text', 'all', 'native', 510, '80,2', 0,
(2, 'sql1', 'sql1', 'show', 'text', 'all', 'native', 510, '80,1,350', 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, '80,2', 0,
(2, 'parameter', 'Parameter', 'show', 'text', 'all', 'native', 520, '80,1,350', 0,
'<a tabindex="-1" href="{{documentation:Y}}#fe-parameter-attributes">Info</a>',
'', '', '', '', 103, '', 'no', '', '', '', '', '', 'none');
......@@ -642,10 +646,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',
'80,2', '', 'yes', '', '', ''),
'80,1,350', '', 'yes', '', '', ''),
(4, 'content', '{{SELECT IF("{{type:FR:alnumx}}"="mail","Mail body","URL") }}', 'show', '', 'text', 'none',
'all', 70,
'', '80,2',
'', '80,1,350',
'Website: URL absolute like "http://..." or relative like "?id=pagealias..."<br>Mail: Static Body or &#123;{SELECT ...&#125;}',
'yes', '', '', ''),
......@@ -660,7 +664,7 @@ 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, '', '80,2', '', 'no',
(4, 'lastStatus', 'Laststatus', 'readonly', '', 'text', 'specialchar', 'alnumx', 130, '', '80,1,350', '', 'no',
'3',
'9',
'0'),
......
......@@ -201,58 +201,6 @@ class HelperFormElementTest extends TestCase {
$this->assertEquals('{"red":18,"green":52,"blue":86}', $result, "Expect white");
}
public function testTextareaAutoHeight() {
$result = HelperFormElement::textareaAutoHeight([], '');
$this->assertEquals('1', $result);
$result = HelperFormElement::textareaAutoHeight([1], '');
$this->assertEquals('1', $result);
$result = HelperFormElement::textareaAutoHeight([1, 0], '');
$this->assertEquals('1', $result);
$result = HelperFormElement::textareaAutoHeight([1, 1], '');
$this->assertEquals('1', $result);
$result = HelperFormElement::textareaAutoHeight([1, 2], '');
$this->assertEquals('2', $result);
$result = HelperFormElement::textareaAutoHeight([], 'Expect white\nExpect white Expect white Expect white\nExpect white');
$this->assertEquals('1', $result);
$result = HelperFormElement::textareaAutoHeight([20], 'Expect white\nExpect white Expect white Expect white\nExpect white');
$this->assertEquals('1', $result);
$result = HelperFormElement::textareaAutoHeight([20, 0], 'Expect white\nExpect white Expect white Expect white\nExpect white');
$this->assertEquals('1', $result);
$result = HelperFormElement::textareaAutoHeight([20, 1], 'Expect white\nExpect white Expect white Expect white\nExpect white');
$this->assertEquals('1', $result);
$result = HelperFormElement::textareaAutoHeight([20, 2], 'Expect white\nExpect white Expect white Expect white\nExpect white');
$this->assertEquals('2', $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, 2], "Expect white\nExpect white\nExpect white");
$this->assertEquals('2', $result);
$result = HelperFormElement::textareaAutoHeight([20, 1, 10], "Expect white\nExpect white\nExpect white");
$this->assertEquals('3', $result);
$result = HelperFormElement::textareaAutoHeight([20, 1, 10], "Expect white\nExpect white Expect white Expect white\nExpect white");
$this->assertEquals('4', $result);
}
/**
* @expectedException \UserFormException
*
......
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