Skip to content

Commit 3d61afc

Browse files
committed
update
1 parent b0833d4 commit 3d61afc

File tree

3 files changed

+29
-4
lines changed

3 files changed

+29
-4
lines changed

src/Checkboxes.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -135,9 +135,8 @@ public function renderDom(\DOMDocument $doc): \DOMElement
135135
$checkbox->setAttribute('checked', 'checked');
136136
}
137137
$wrapper->appendChild($checkbox);
138-
$label = $doc->createElement('label');
138+
$label = $doc->createElement('label', $value);
139139
$label->setAttribute('for', $this->name . '_' . $key);
140-
$label->textContent = $value;
141140
$wrapper->appendChild($label);
142141
}
143142
return $wrapper;

src/Input.php

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,9 @@ class Input implements Control
1515
protected string $type = 'text';
1616
protected string $placeholder = '';
1717

18+
/** @var array<string|int,string> $options */
19+
protected array $options = [];
20+
1821
protected bool $disabled = false;
1922
protected bool $readonly = false;
2023
protected bool $required = false;
@@ -85,6 +88,15 @@ public function placeholder(string $placeholder): self
8588
return $this;
8689
}
8790

91+
/**
92+
* @param array<string|int,string> $options
93+
*/
94+
public function options(array $options): self
95+
{
96+
$this->options = $options;
97+
return $this;
98+
}
99+
88100
/**
89101
* @param array<string, string|string[]|null> $data
90102
*/
@@ -154,6 +166,21 @@ public function renderDom(DOMDocument $doc): DOMElement
154166
if ($this->autocomplete) {
155167
$input->setAttribute('autocomplete', 'on');
156168
}
169+
if ($this->options) {
170+
$input->setAttribute('list', $this->name . '-options');
171+
$datalist = $doc->createElement('datalist');
172+
$datalist->setAttribute('id', $this->name . '-options');
173+
foreach ($this->options as $value => $label) {
174+
$option = $doc->createElement('option', $label);
175+
if (is_int($value)) {
176+
$option->setAttribute('value', $label);
177+
} else {
178+
$option->setAttribute('value', $value);
179+
}
180+
$datalist->appendChild($option);
181+
}
182+
$doc->appendChild($datalist);
183+
}
157184
return $input;
158185
}
159186
}

src/Select.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -157,12 +157,11 @@ public function renderDom(\DOMDocument $doc): \DOMElement
157157
$select->setAttribute('required', 'required');
158158
}
159159
foreach ($this->options as $key => $value) {
160-
$option = $doc->createElement('option');
160+
$option = $doc->createElement('option', $value);
161161
$option->setAttribute('value', strval($key));
162162
if (in_array($key, $this->values)) {
163163
$option->setAttribute('selected', 'selected');
164164
}
165-
$option->textContent = $value;
166165
$select->appendChild($option);
167166
}
168167
return $select;

0 commit comments

Comments
 (0)