From 81f6f7ddf3f94a6c2ed70f286d29aa1207a5932a Mon Sep 17 00:00:00 2001 From: Stephen Cameron Date: Wed, 1 Apr 2020 22:41:05 +0200 Subject: [PATCH] WIP #3445 @8 --- wp-content/mu-plugins/cube/src/Forms/Base.php | 75 ++++++++++++-- .../cube/src/Forms/Consultation.php | 47 +++++++++ .../assets/styles/common/spacing.styl | 4 +- .../assets/styles/components/forms.styl | 55 ++++++++--- .../views/forms/consultation.blade.php | 97 +++++++++++++++++-- 5 files changed, 245 insertions(+), 33 deletions(-) diff --git a/wp-content/mu-plugins/cube/src/Forms/Base.php b/wp-content/mu-plugins/cube/src/Forms/Base.php index 803675e..f01488c 100644 --- a/wp-content/mu-plugins/cube/src/Forms/Base.php +++ b/wp-content/mu-plugins/cube/src/Forms/Base.php @@ -11,6 +11,7 @@ class Base const CHECKBOX = 'checkbox'; const DATE = 'date'; const RADIO = 'radio'; + const SELECT = 'select'; const TEXT = 'text'; const TEXTAREA = 'textarea'; @@ -23,27 +24,43 @@ class Base */ public function field($name, $settings = []) { + $field = $this->getField($name); + if (!$field) return false; + $default_settings = [ - 'hide_labels' => false, - 'placeholder' => true, + 'class' => '', + 'title_class' => '', + 'input_class' => '', + 'show_title' => true, + 'show_labels' => true, + 'placeholder' => $field['title'], + 'field_before' => '', + 'field_after' => '', ]; - $settings = array_merge($default_settings, $settings); - $field = $this->getField($name); - if (!$field) return false; + $res = ''; - $res = '
'. $field['title'] .'
'; + if ($settings['show_title']) { + $res .= '
'. $field['title'] .'
'; + } + + // Special input styling for checkbox / radio fields + if (in_array($field['type'], [self::BINARY, self::CHECKBOX, self::RADIO])) { + $settings['input_class'] .= ' custom-checkbox'; + } if (method_exists($this, $field['type'])) { - $res .= '
'; + $res .= '
'; + $res .= $settings['field_before']; $res .= $this->{$field['type']}($name, $settings); + $res .= $settings['field_after']; $res .= '
'; } else { $res .= 'Unrecognised field: '. $field['type']; } - return '
'. $res .'
'; + return '
'. $res .'
'; } /** @@ -65,7 +82,7 @@ class Base $res .= '