From 68651141188c4a604028eaeb317e4b3eb3a045be Mon Sep 17 00:00:00 2001 From: Sami Mokaddem Date: Wed, 8 Dec 2021 11:08:40 +0100 Subject: [PATCH] chg: [genericElements:form] Support of more option and radio input --- .../element/genericElements/Form/Fields/genericField.php | 4 +++- templates/element/genericElements/Form/fieldScaffold.php | 2 +- templates/element/genericElements/Form/genericForm.php | 7 ++++++- 3 files changed, 10 insertions(+), 3 deletions(-) diff --git a/templates/element/genericElements/Form/Fields/genericField.php b/templates/element/genericElements/Form/Fields/genericField.php index 38f05a4..4174c5b 100644 --- a/templates/element/genericElements/Form/Fields/genericField.php +++ b/templates/element/genericElements/Form/Fields/genericField.php @@ -1,5 +1,7 @@ FormFieldMassage->prepareFormElement($this->Form, $params, $fieldData); ?> diff --git a/templates/element/genericElements/Form/fieldScaffold.php b/templates/element/genericElements/Form/fieldScaffold.php index 818e6e6..32b339b 100644 --- a/templates/element/genericElements/Form/fieldScaffold.php +++ b/templates/element/genericElements/Form/fieldScaffold.php @@ -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) { diff --git a/templates/element/genericElements/Form/genericForm.php b/templates/element/genericElements/Form/genericForm.php index ba4146e..446cc48 100644 --- a/templates/element/genericElements/Form/genericForm.php +++ b/templates/element/genericElements/Form/genericForm.php @@ -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' => '', 'checkbox' => '', 'checkboxFormGroup' => '{{label}}', + 'radio' => '', + 'radioWrapper' => '{{label}}', 'formGroup' => '
{{input}}{{error}}
', 'nestingLabel' => '{{hidden}}
{{text}}
{{input}}
', '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);