Skip to content

Commit f49d0c8

Browse files
Merge pull request #1368 from rasstislav/fix-textarea-max-length
FIX Allow setMaxLength for all field types (TextField, TextareaField)
2 parents 12d7792 + 7fd8626 commit f49d0c8

File tree

2 files changed

+3
-2
lines changed

2 files changed

+3
-2
lines changed

code/Model/EditableFormField/EditableTextField.php

+2-1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
namespace SilverStripe\UserForms\Model\EditableFormField;
44

5+
use SilverStripe\Core\ClassInfo;
56
use SilverStripe\Forms\DropdownField;
67
use SilverStripe\Forms\FieldGroup;
78
use SilverStripe\Forms\FieldList;
@@ -185,7 +186,7 @@ protected function updateFormField($field)
185186
}
186187

187188
if (is_numeric($this->MaxLength) && $this->MaxLength > 0) {
188-
if ($field instanceof TextField) {
189+
if (ClassInfo::hasMethod($field, 'setMaxLength')) {
189190
$field->setMaxLength((int) $this->MaxLength);
190191
}
191192
$field->setAttribute('data-rule-maxlength', (int) $this->MaxLength);

tests/php/Model/EditableFormFieldTest.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -232,7 +232,7 @@ public function testLengthRange()
232232
// textarea
233233
$textField->Rows = 3;
234234
$attributes = $textField->getFormField()->getAttributes();
235-
$this->assertFalse(isset($attributes['maxLength']));
235+
$this->assertEquals(20, $attributes['maxlength']);
236236
$this->assertEquals(10, $attributes['data-rule-minlength']);
237237
$this->assertEquals(20, $attributes['data-rule-maxlength']);
238238
}

0 commit comments

Comments
 (0)