Skip to content

Commit

Permalink
Element // fix attributesForView to return correct "disabled"-state i…
Browse files Browse the repository at this point in the history
…n case the parent is disabled.

View\FormRow // add new selector "form-row--is-disabled".
  • Loading branch information
Chrico committed Sep 25, 2023
1 parent 7bdbb76 commit a9df17e
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/Element/Element.php
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,7 @@ public function attributesForView(): array
$id = $parentAttributes['id'];
$name = $parentAttributes['name'];

$attributes['disabled'] = $this->isDisabled();
$attributes['id'] = $id . '_' . $attributes['id'];
$attributes['name'] = $name . '[' . $attributes['name'] . ']';
}
Expand Down
3 changes: 3 additions & 0 deletions src/View/FormRow.php
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,9 @@ public function render(ElementInterface $element): string
if ($errors !== '') {
$rowAttributes['class'] .= ' form-row--has-errors';
}
if ($element->isDisabled()) {
$rowAttributes['class'] .= 'form-row--is-disabled';
}
if ($element->type() === 'hidden') {
$rowAttributes['class'] .= ' hidden';
}
Expand Down
2 changes: 2 additions & 0 deletions tests/phpunit/Unit/View/FormTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,8 @@ public function testRender(): void
->andReturn('text');
$element_stub->allows('attributesForView')
->andReturn([]);
$element_stub->allows('isDisabled')
->andReturnFalse();

$form_stub = Mockery::mock(FormInterface::class, ElementInterface::class, CollectionElementInterface::class);
$form_stub->allows('name')
Expand Down

0 comments on commit a9df17e

Please sign in to comment.