Skip to content

Commit

Permalink
FIX Allow setMaxLength for all field types (TextField, TextareaField)
Browse files Browse the repository at this point in the history
  • Loading branch information
rasstislav committed Feb 8, 2025
1 parent 5b71b31 commit c8eff3e
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 4 deletions.
4 changes: 1 addition & 3 deletions code/Model/EditableFormField/EditableTextField.php
Original file line number Diff line number Diff line change
Expand Up @@ -185,9 +185,7 @@ protected function updateFormField($field)
}

if (is_numeric($this->MaxLength) && $this->MaxLength > 0) {
if ($field instanceof TextField) {
$field->setMaxLength((int) $this->MaxLength);
}
$field->setMaxLength((int) $this->MaxLength);
$field->setAttribute('data-rule-maxlength', (int) $this->MaxLength);
}

Expand Down
2 changes: 1 addition & 1 deletion tests/php/Model/EditableFormFieldTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,7 @@ public function testLengthRange()
// textarea
$textField->Rows = 3;
$attributes = $textField->getFormField()->getAttributes();
$this->assertFalse(isset($attributes['maxLength']));
$this->assertEquals(20, $attributes['maxlength']);
$this->assertEquals(10, $attributes['data-rule-minlength']);
$this->assertEquals(20, $attributes['data-rule-maxlength']);
}
Expand Down

0 comments on commit c8eff3e

Please sign in to comment.