Merge pull request #10183 from kinglozzer/readonly-extraclass

FIX Ensure extra classes are copied over to readonly/disabled fields
This commit is contained in:
Michal Kleiner 2022-01-15 10:27:39 +13:00 committed by GitHub
commit 3963dd4ecc
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 12 additions and 3 deletions

View File

@ -1355,13 +1355,14 @@ class FormField extends RequestHandler
$field = $classOrCopy::create($this->name); $field = $classOrCopy::create($this->name);
} }
$extraClasses = $this->extraClasses ? array_values($this->extraClasses) : [];
$field $field
->setValue($this->value) ->setValue($this->value)
->setForm($this->form) ->setForm($this->form)
->setTitle($this->Title()) ->setTitle($this->Title())
->setLeftTitle($this->LeftTitle()) ->setLeftTitle($this->LeftTitle())
->setRightTitle($this->RightTitle()) ->setRightTitle($this->RightTitle())
->addExtraClass($this->extraClass) // Don't use extraClass(), since this merges calculated values ->addExtraClass(implode(' ', $extraClasses)) // Don't use extraClass(), since this merges calculated values
->setDescription($this->getDescription()); ->setDescription($this->getDescription());
// Only include built-in attributes, ignore anything set through getAttributes(). // Only include built-in attributes, ignore anything set through getAttributes().

View File

@ -259,6 +259,14 @@ class FormFieldTest extends SapphireTest
$this->assertStringNotContainsString('readonly="readonly"', $field->getAttributesHTML()); $this->assertStringNotContainsString('readonly="readonly"', $field->getAttributesHTML());
} }
public function testReadonlyPreservesExtraClass()
{
$field = new FormField('MyField');
$field->addExtraClass('myextraclass1')->addExtraClass('myextraclass2');
$field->setReadonly(true);
$this->assertStringContainsString('myextraclass1 myextraclass2', $field->getAttributesHTML());
}
public function testDisabled() public function testDisabled()
{ {
$field = new FormField('MyField'); $field = new FormField('MyField');