Skip to content

Commit 6d276ac

Browse files
committed
Add fieldAsLabeledInput
1 parent 254bb0f commit 6d276ac

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

Ajax/semantic/widgets/base/FieldAsTrait.php

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -204,6 +204,24 @@ public function fieldAsInput($index, $attributes = NULL) {
204204
}, $index, $attributes, "input");
205205
}
206206

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+
207225
public function fieldAsDataList($index, ?array $items = [], $attributes = NULL) {
208226
return $this->_fieldAs(function ($id, $name, $value, $caption) use ($attributes, $items) {
209227
$input = new HtmlFormInput($id, $caption, "text", $value);

0 commit comments

Comments
 (0)