Skip to content

Commit

Permalink
Helpers::prepareAttrs() fixed
Browse files Browse the repository at this point in the history
  • Loading branch information
dg committed May 13, 2020
1 parent 9810d26 commit 5297f35
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 8 deletions.
14 changes: 7 additions & 7 deletions src/Forms/Helpers.php
Original file line number Diff line number Diff line change
Expand Up @@ -207,15 +207,15 @@ private static function prepareAttrs(?array $attrs, string $name): array
{
$dynamic = [];
foreach ((array) $attrs as $k => $v) {
$p = str_split($k, strlen($k) - 1);
if ($p[1] === '?' || $p[1] === ':') {
unset($attrs[$k], $attrs[$p[0]]);
if ($p[1] === '?') {
$dynamic[$p[0]] = array_fill_keys((array) $v, true);
if ($k[-1] === '?' || $k[-1] === ':') {
$p = substr($k, 0, -1);
unset($attrs[$k], $attrs[$p]);
if ($k[-1] === '?') {
$dynamic[$p] = array_fill_keys((array) $v, true);
} elseif (is_array($v) && $v) {
$dynamic[$p[0]] = $v;
$dynamic[$p] = $v;
} else {
$attrs[$p[0]] = $v;
$attrs[$p] = $v;
}
}
}
Expand Down
3 changes: 2 additions & 1 deletion tests/Forms/Helpers.createSelectBox.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -58,14 +58,15 @@ test(function () {
);

Assert::same(
'<select><option title="Hello" style="color:blue" value="a" selected>First</option><option title="Hello" style="color:blue" value="b" disabled>Second</option></select>',
'<select><option title="Hello" style="color:blue" a="b" value="a" selected>First</option><option title="Hello" style="color:blue" a="b" value="b" disabled>Second</option></select>',
(string) Helpers::createSelectBox(
['a' => 'First', 'b' => 'Second'],
[
'disabled:' => ['b' => true],
'selected?' => ['a'],
'title' => 'Hello',
'style' => ['color' => 'blue'],
'a' => 'b',
]
)
);
Expand Down

0 comments on commit 5297f35

Please sign in to comment.