21
21
*/
22
22
abstract class ChoiceControl extends BaseControl
23
23
{
24
+ /** @var bool[] */
25
+ protected array $ disabledChoices = [];
24
26
private bool $ checkDefaultValue = true ;
25
27
26
28
/** @var list<array{int|string, string|\Stringable}> */
@@ -77,7 +79,7 @@ public function setValue($value): static
77
79
public function getValue (): mixed
78
80
{
79
81
return $ this ->value !== null
80
- && !isset ($ this ->disabled [$ this ->value ])
82
+ && !isset ($ this ->disabledChoices [$ this ->value ])
81
83
&& ([$ res ] = Arrays::first ($ this ->choices , fn ($ choice ) => $ choice [0 ] === $ this ->value ))
82
84
? $ res
83
85
: null ;
@@ -130,7 +132,7 @@ public function getItems(): array
130
132
public function getSelectedItem (): mixed
131
133
{
132
134
return $ this ->value !== null
133
- && !isset ($ this ->disabled [$ this ->value ])
135
+ && !isset ($ this ->disabledChoices [$ this ->value ])
134
136
&& ([, $ res ] = Arrays::first ($ this ->choices , fn ($ choice ) => $ choice [0 ] === $ this ->value ))
135
137
? $ res
136
138
: null ;
@@ -143,12 +145,11 @@ public function getSelectedItem(): mixed
143
145
public function setDisabled (bool |array $ value = true ): static
144
146
{
145
147
if (!is_array ($ value )) {
148
+ $ this ->disabledChoices = [];
146
149
return parent ::setDisabled ($ value );
147
150
}
148
-
149
- parent ::setDisabled (false );
150
- $ this ->disabled = array_fill_keys ($ value , value: true );
151
- return $ this ;
151
+ $ this ->disabledChoices = array_fill_keys ($ value , value: true );
152
+ return parent ::setDisabled (false );
152
153
}
153
154
154
155
0 commit comments