@@ -204,6 +204,24 @@ public function fieldAsInput($index, $attributes = NULL) {
204
204
}, $ index , $ attributes , "input " );
205
205
}
206
206
207
+ public function fieldAsLabeledInput ($ index , $ attributes = NULL ) {
208
+ return $ this ->_fieldAs (function ($ id , $ name , $ value , $ caption ) use ($ attributes ) {
209
+ $ input = new HtmlFormInput ($ id , '' , 'text ' , $ value , $ caption );
210
+ $ required = '' ;
211
+ if (isset ($ attributes ['rules ' ])) {
212
+ $ rules = json_encode ($ attributes ['rules ' ]);
213
+ if (strpos ($ rules , 'empty ' ) !== false ) {
214
+ $ required = 'required ' ;
215
+ }
216
+ }
217
+ $ input ->getField ()
218
+ ->labeled ($ caption )
219
+ ->setTagName ('label ' )
220
+ ->addClass ($ required );
221
+ return $ this ->_prepareFormFields ($ input , $ name , $ attributes );
222
+ }, $ index , $ attributes , 'input ' );
223
+ }
224
+
207
225
public function fieldAsDataList ($ index , ?array $ items = [], $ attributes = NULL ) {
208
226
return $ this ->_fieldAs (function ($ id , $ name , $ value , $ caption ) use ($ attributes , $ items ) {
209
227
$ input = new HtmlFormInput ($ id , $ caption , "text " , $ value );
0 commit comments