@@ -10,9 +10,9 @@ class SelectOrType implements Control
1010 use HtmlElement;
1111
1212 protected string $ name = '' ;
13- /** @var array<string,string > $options */
13+ /** @var array<string> $options */
1414 protected array $ options = [];
15- /** @var array<string,string > $originalOptions */
15+ /** @var array<string> $originalOptions */
1616 protected array $ originalOptions = [];
1717 protected string $ value = '' ;
1818 protected string $ placeholder = '' ;
@@ -77,12 +77,12 @@ public function autocomplete(string $value): self
7777 */
7878 public function options (array $ options ): self
7979 {
80- $ this ->options = array_combine ( $ options, $ options ) ;
81- if (!isset ( $ this ->options [ '' ] )) {
82- $ this ->options = [ '' => ' ... ' ] + $ this -> options ; // Add empty option if not present
80+ $ this ->options = $ options ;
81+ if (!in_array ( '' , $ this ->options )) {
82+ array_unshift ( $ this ->options , '' ) ; // Add empty option if not present
8383 }
8484 $ this ->originalOptions = $ this ->options ;
85- $ this ->options = $ this -> options + [ ' !type! ' => $ this ->typeCaption ] ;
85+ $ this ->options [] = $ this ->typeCaption ;
8686 return $ this ;
8787 }
8888
@@ -91,9 +91,9 @@ public function value(string $value): self
9191 $ this ->value = $ value ;
9292 $ this ->options = $ this ->originalOptions ;
9393 if ($ this ->value && !in_array ($ this ->value , $ this ->options )) {
94- $ this ->options [$ this -> value ] = $ this ->value ;
94+ $ this ->options [] = $ this ->value ;
9595 }
96- $ this ->options = $ this -> options + [ ' !type! ' => $ this ->typeCaption ] ;
96+ $ this ->options [] = $ this ->typeCaption ;
9797 return $ this ;
9898 }
9999
@@ -106,7 +106,8 @@ public function placeholder(string $placeholder): self
106106 public function typeCaption (string $ typeCaption ): self
107107 {
108108 $ this ->typeCaption = $ typeCaption ;
109- $ this ->options ['!type! ' ] = $ this ->typeCaption ;
109+ array_pop ($ this ->options );
110+ array_push ($ this ->options , $ this ->typeCaption );
110111 return $ this ;
111112 }
112113
@@ -157,10 +158,11 @@ public function renderDom(\DOMDocument $doc): \DOMElement
157158 $ select ->setAttribute ('required ' , 'required ' );
158159 }
159160 $ i = 0 ;
160- foreach ($ this ->options as $ key => $ value ) {
161- $ option = $ doc ->createElement ('option ' , $ value );
162- $ option ->setAttribute ('value ' , strval ($ key ));
163- if ($ key == $ this ->value ) {
161+ foreach ($ this ->options as $ value ) {
162+ $ caption = $ value ?: '... ' ;
163+ $ option = $ doc ->createElement ('option ' , $ caption );
164+ $ option ->setAttribute ('value ' , $ value );
165+ if ($ value == $ this ->value ) {
164166 $ option ->setAttribute ('selected ' , 'selected ' );
165167 }
166168 $ select ->appendChild ($ option );
0 commit comments