@@ -12,44 +12,28 @@ class Field
1212 protected ?Label $ label = null ;
1313 protected ?Control $ control = null ;
1414 protected ?Error $ error = null ;
15- /** @var Validator[] */
15+ /** @var Validator[] $validators */
1616 protected array $ validators = [];
1717
1818 protected bool $ hideError = false ;
1919
2020 protected bool $ disabled = false ;
21- protected bool $ readonly = false ;
22- protected bool $ required = false ;
23- protected bool $ autofocus = false ;
2421
2522 public function __construct ()
2623 {
2724 $ this ->tag ('div ' );
28- $ this ->class ('form-group ' );
2925 }
3026
3127 public function disabled (): self
3228 {
3329 $ this ->class ('disabled ' );
3430 $ this ->disabled = true ;
35- return $ this ;
36- }
37-
38- public function readonly (): self
39- {
40- $ this ->readonly = true ;
41- return $ this ;
42- }
43-
44- public function required (): self
45- {
46- $ this ->required = true ;
47- return $ this ;
48- }
49-
50- public function autofocus (): self
51- {
52- $ this ->autofocus = true ;
31+ if ($ this ->label ) {
32+ $ this ->label ->disabled ();
33+ }
34+ if ($ this ->control ) {
35+ $ this ->control ->disabled ();
36+ }
5337 return $ this ;
5438 }
5539
@@ -98,13 +82,13 @@ public function fill(array $data): void
9882 }
9983
10084 /**
101- * @return array<string, string|string[]|null>
85+ * @return array<string, string|string[]|null> $data
10286 */
103- public function extract (): array
87+ public function extract (bool $ withNulls = false ): array
10488 {
10589 $ data = [];
10690 if ($ this ->control && !$ this ->disabled ) {
107- $ data = $ this ->control ->extract ();
91+ $ data = $ this ->control ->extract ($ withNulls );
10892 }
10993 return $ data ;
11094 }
@@ -126,9 +110,9 @@ public function validate(): string
126110 public function setError (string $ message ): void
127111 {
128112 if ($ message ) {
129- $ this ->addClass ('has- error ' );
113+ $ this ->addClass ('error ' );
130114 } else {
131- $ this ->removeClass ('has- error ' );
115+ $ this ->removeClass ('error ' );
132116 }
133117 if ($ this ->label ) {
134118 $ this ->label ->setError ($ message );
@@ -167,18 +151,6 @@ public function renderDom(\DOMDocument $doc): \DOMElement
167151 }
168152 if ($ this ->control ) {
169153 $ control = $ this ->control ->renderDom ($ doc );
170- if ($ this ->disabled ) {
171- $ control ->setAttribute ('disabled ' , 'disabled ' );
172- }
173- if ($ this ->readonly ) {
174- $ control ->setAttribute ('readonly ' , 'readonly ' );
175- }
176- if ($ this ->required ) {
177- $ control ->setAttribute ('required ' , 'required ' );
178- }
179- if ($ this ->autofocus ) {
180- $ control ->setAttribute ('autofocus ' , 'autofocus ' );
181- }
182154 $ field ->appendChild ($ control );
183155 }
184156 if ($ this ->error ) {
0 commit comments