[FEATURE] Support maximum length in TextElement 06/35506/4
authorGeorg Ringer <georg.ringer@gmail.com>
Tue, 16 Dec 2014 06:47:32 +0000 (07:47 +0100)
committerAlexander Opitz <opitz.alexander@googlemail.com>
Tue, 16 Dec 2014 10:17:47 +0000 (11:17 +0100)
Like the InputElement, also the TextElement should support the
"max" option for specifying a maximum length attribute.

Resolves: #24906
Releases: master
Change-Id: I21435150ed61bd0b0b3b1f6e8bcbb1c50fb0f6e2
Reviewed-on: http://review.typo3.org/35506
Reviewed-by: Andreas Fernandez <a.fernandez@scripting-base.de>
Tested-by: Andreas Fernandez <a.fernandez@scripting-base.de>
Reviewed-by: Mathias Brodala <mbrodala@pagemachine.de>
Reviewed-by: Alexander Opitz <opitz.alexander@googlemail.com>
Tested-by: Alexander Opitz <opitz.alexander@googlemail.com>
typo3/sysext/backend/Classes/Form/Element/TextElement.php
typo3/sysext/core/Documentation/Changelog/master/Feature-24906-MaxForTextElement.rst [new file with mode: 0644]

index cb4577f..3e7064d 100644 (file)
@@ -189,11 +189,15 @@ class TextElement extends AbstractFormElement {
                                        }
                                }
                                $textOnChange = implode('', $additionalInformation['fieldChangeFunc']);
+                               $additionalAttributes = '';
+                               if (isset($config['max']) && (int)$config['max'] > 0) {
+                                       $additionalAttributes = ' maxlength="' . (int)$config['max'] . '"';
+                               }
                                $item .= '
                                                        <textarea ' . 'id="' . str_replace('.', '', uniqid('tceforms-textarea-', TRUE)) . '" ' . 'name="' . $additionalInformation['itemFormElName']
                                        . '"' . $formWidthText . $class . ' ' . 'rows="' . $rows . '" ' . 'wrap="' . $wrap . '" ' . 'onchange="'
                                        . htmlspecialchars($textOnChange) . '"' . $this->formEngine->getPlaceholderAttribute($table, $field, $config, $row)
-                                       . $additionalInformation['onFocus'] . '>' . GeneralUtility::formatForTextarea($additionalInformation['itemFormElValue']) . '</textarea>';
+                                       . $additionalInformation['onFocus'] . $additionalAttributes . '>' . GeneralUtility::formatForTextarea($additionalInformation['itemFormElValue']) . '</textarea>';
                                $item = $this->formEngine->renderWizards(
                                        array($item, $altItem),
                                        $config['wizards'],
diff --git a/typo3/sysext/core/Documentation/Changelog/master/Feature-24906-MaxForTextElement.rst b/typo3/sysext/core/Documentation/Changelog/master/Feature-24906-MaxForTextElement.rst
new file mode 100644 (file)
index 0000000..57cd540
--- /dev/null
@@ -0,0 +1,22 @@
+================================================================
+Feature: #24906 - Configuration for maximum chars in TextElement
+================================================================
+
+Description
+===========
+
+The Textelement supports now the option ``max`` to render the attribute maxlength for textelements,
+
+The new option can be set like this:
+
+.. code-block::
+
+       'teaser' => array(
+               'label' => 'Teaser',
+               'config' => array(
+                       'type' => 'text',
+                       'cols' => 60,
+                       'rows' => 2,
+                       'max' => '30',
+               )
+       ),
\ No newline at end of file