Skip to content

Commit 43a1cc7

Browse files
committed
SelectBox, MultiSelectBox: added setOptionAttribute()
1 parent 56b6ed7 commit 43a1cc7

File tree

4 files changed

+20
-2
lines changed

4 files changed

+20
-2
lines changed

src/Forms/Controls/MultiSelectBox.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,14 @@ public function addOptionAttributes(array $attributes)
8484
}
8585

8686

87+
/** @return static */
88+
public function setOptionAttribute(string $name, $value = true)
89+
{
90+
$this->optionAttributes[$name] = $value;
91+
return $this;
92+
}
93+
94+
8795
public function getOptionAttributes(): array
8896
{
8997
return $this->optionAttributes;

src/Forms/Controls/SelectBox.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,14 @@ public function addOptionAttributes(array $attributes)
117117
}
118118

119119

120+
/** @return static */
121+
public function setOptionAttribute(string $name, $value = true)
122+
{
123+
$this->optionAttributes[$name] = $value;
124+
return $this;
125+
}
126+
127+
120128
public function isOk(): bool
121129
{
122130
return $this->isDisabled()

tests/Forms/Controls.MultiSelectBox.render.phpt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,8 @@ test(function () {
152152
1 => 'First',
153153
2 => 'Second',
154154
])->setValue(1);
155-
$input->addOptionAttributes(['bar' => 'b', 'selected?' => 2, 'foo:' => [1 => 'a', 2 => 'b']]);
155+
$input->addOptionAttributes(['bar' => 'b', 'selected?' => 2]);
156156
$input->addOptionAttributes(['bar' => 'c']);
157+
$input->setOptionAttribute('foo:', [1 => 'a', 2 => 'b']);
157158
Assert::same('<select name="list[]" id="frm-list" multiple><option bar="c" value="1" selected foo="a">First</option><option bar="c" value="2" foo="b">Second</option></select>', (string) $input->getControl());
158159
});

tests/Forms/Controls.SelectBox.render.phpt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,8 @@ test(function () {
152152
1 => 'First',
153153
2 => 'Second',
154154
])->setValue(1);
155-
$input->addOptionAttributes(['bar' => 'b', 'selected?' => 2, 'foo:' => [1 => 'a', 2 => 'b']]);
155+
$input->addOptionAttributes(['bar' => 'b', 'selected?' => 2]);
156156
$input->addOptionAttributes(['bar' => 'c']);
157+
$input->setOptionAttribute('foo:', [1 => 'a', 2 => 'b']);
157158
Assert::same('<select name="list" id="frm-list"><option bar="c" value="1" selected foo="a">First</option><option bar="c" value="2" foo="b">Second</option></select>', (string) $input->getControl());
158159
});

0 commit comments

Comments
 (0)