chg: [genericElements:form] Support of more option and radio input

pull/93/head
Sami Mokaddem 2021-12-08 11:08:40 +01:00
parent 296e8b119a
commit 6865114118
No known key found for this signature in database
GPG Key ID: 164C473F627A06FA
3 changed files with 10 additions and 3 deletions

View File

@ -1,5 +1,7 @@
<?php
$params['div'] = false;
$params['class'] .= ' form-control';
if (empty($fieldData['type']) || ($fieldData['type'] !== 'checkbox' && $fieldData['type'] !== 'radio')) {
$params['class'] .= ' form-control';
}
echo $this->FormFieldMassage->prepareFormElement($this->Form, $params, $fieldData);
?>

View File

@ -32,7 +32,7 @@
} else {
$params['class'] = '';
}
if (empty($fieldData['type']) || $fieldData['type'] !== 'checkbox' ) {
if (empty($fieldData['type']) || ($fieldData['type'] !== 'checkbox' && $fieldData['type'] !== 'radio')) {
$params['class'] .= ' form-control';
}
foreach ($fieldData as $k => $fd) {

View File

@ -20,7 +20,7 @@
$entity = isset($entity) ? $entity : null;
$fieldsString = '';
$simpleFieldWhitelist = [
'default', 'type', 'placeholder', 'label', 'empty', 'rows', 'div', 'required', 'templates'
'default', 'type', 'placeholder', 'label', 'empty', 'rows', 'div', 'required', 'templates', 'options', 'value', 'checked'
];
if (empty($data['url'])) {
$data['url'] = ["controller" => $this->request->getParam('controller'), "action" => $this->request->getParam('url')];
@ -37,6 +37,8 @@
'select' => '<select name="{{name}}" {{attrs}}>{{content}}</select>',
'checkbox' => '<input type="checkbox" name="{{name}}" value="{{value}}"{{attrs}}>',
'checkboxFormGroup' => '{{label}}',
'radio' => '<input type="radio" name="{{name}}" value="{{value}}"{{attrs}}>',
'radioWrapper' => '{{label}}',
'formGroup' => '<label class="col-sm-2 col-form-label form-label" {{attrs}}>{{label}}</label><div class="col-sm-10">{{input}}{{error}}</div>',
'nestingLabel' => '{{hidden}}<div class="col-sm-2 form-label">{{text}}</div><div class="col-sm-10">{{input}}</div>',
'option' => '<option value="{{value}}"{{attrs}}>{{text}}</option>',
@ -61,6 +63,9 @@
$formTemplate['formGroup'] = '{{input}}{{label}}';
$fieldData['placeholder'] = !empty($fieldData['label']) ? $fieldData['label'] : h($fieldData['field']);
}
if (!empty($data['templates'])) {
$formTemplate = array_merge($formTemplate, $data['templates']);
}
// we reset the template each iteration as individual fields might override the defaults.
$this->Form->setConfig($formTemplate);
$this->Form->setTemplates($formTemplate);