From 3ad4c5e3a1406029f746877ed030e8dda0dde47f Mon Sep 17 00:00:00 2001 From: Renato Dehnhardt Date: Mon, 11 Jun 2018 11:05:27 +0200 Subject: [PATCH] Set bootstrap 4 as default --- src/FormBuilder.php | 66 +++++++++++++++++++-------------------------- 1 file changed, 28 insertions(+), 38 deletions(-) diff --git a/src/FormBuilder.php b/src/FormBuilder.php index 5cde6c9..60479b7 100644 --- a/src/FormBuilder.php +++ b/src/FormBuilder.php @@ -22,13 +22,7 @@ class FormBuilder extends IlluminateFormBuilder public function openGroup($name, $label = null, $options = array()) { $options = $this->appendClassToOptions('form-group', $options); - $this->groupStack[] = $name; - - if ($this->hasErrors($name)) { - $options = $this->appendClassToOptions('has-error', $options); - } - $label = $label ? $this->label($name, $label) : ''; return 'html->attributes($options) . '>' . $label; @@ -85,6 +79,10 @@ public function input($type, $name, $value = null, $options = array()) $options = $this->appendClassToOptions('form-control', $options); } + if ($this->hasErrors($name)) { + $options = $this->appendClassToOptions('is-invalid', $options); + } + return parent::input($type, $name, $value, $options); } @@ -103,39 +101,11 @@ public function select($name, $list = [], $selected = null, array $selectAttribu { $selectAttributes = $this->appendClassToOptions('form-control', $selectAttributes); - return parent::select($name, $list, $selected, $selectAttributes, $optionsAttributes, $optgroupsAttributes); - } - - /** - * Create a select box field. - * @param $name - * @param $class - * @param array $first - * @param array $columns - * @param null $selected - * @param array $options - * @return \Illuminate\Support\HtmlString - */ - public function lookup($name, $class, array $first = [], array $columns = [], $selected = null, $options = array()) - { - $options = $this->appendClassToOptions('form-control', $options); - - if (!array_key_exists('label', $columns)) { - $columns['label'] = 'title'; - } - - if (!array_key_exists('value', $columns)) { - $columns['value'] = 'id'; - } - - $model = new $class; - $list = $model->lists($columns['label'], $columns['value']); - - if (count($first)) { - $list = array_merge($first, $list->toArray()); + if ($this->hasErrors($name)) { + $selectAttributes = $this->appendClassToOptions('is-invalid', $selectAttributes); } - return parent::select($name, $list, $selected, $options); + return parent::select($name, $list, $selected, $selectAttributes, $optionsAttributes, $optgroupsAttributes); } /** @@ -199,6 +169,10 @@ protected function checkable($type, $name, $value, $checked, $options) */ public function checkbox($name, $value = 1, $label = null, $checked = null, $options = array()) { + if ($this->hasErrors($name)) { + $options = $this->appendClassToOptions('is-invalid', $options); + } + $checkable = parent::checkbox($name, $value, $checked, $options); return $this->wrapCheckable($label, 'checkbox', $checkable); @@ -216,6 +190,10 @@ public function checkbox($name, $value = 1, $label = null, $checked = null, $opt */ public function radio($name, $value = null, $label = null, $checked = null, $options = array()) { + if ($this->hasErrors($name)) { + $options = $this->appendClassToOptions('is-invalid', $options); + } + $checkable = parent::radio($name, $value, $checked, $options); return $this->wrapCheckable($label, 'radio', $checkable); @@ -233,6 +211,10 @@ public function radio($name, $value = null, $label = null, $checked = null, $opt */ public function inlineCheckbox($name, $value = 1, $label = null, $checked = null, $options = array()) { + if ($this->hasErrors($name)) { + $options = $this->appendClassToOptions('is-invalid', $options); + } + $checkable = parent::checkbox($name, $value, $checked, $options); return $this->wrapInlineCheckable($label, 'checkbox', $checkable); @@ -250,6 +232,10 @@ public function inlineCheckbox($name, $value = 1, $label = null, $checked = null */ public function inlineRadio($name, $value = null, $label = null, $checked = null, $options = array()) { + if ($this->hasErrors($name)) { + $options = $this->appendClassToOptions('is-invalid', $options); + } + $checkable = parent::radio($name, $value, $checked, $options); return $this->wrapInlineCheckable($label, 'radio', $checkable); @@ -267,6 +253,10 @@ public function textarea($name, $value = null, $options = array()) { $options = $this->appendClassToOptions('form-control', $options); + if ($this->hasErrors($name)) { + $options = $this->appendClassToOptions('is-invalid', $options); + } + return parent::textarea($name, $value, $options); } @@ -330,7 +320,7 @@ private function getFormattedErrors($name) $errors = $this->session->get('errors'); - return $errors->first($this->transformKey($name), '

:message

'); + return $errors->first($this->transformKey($name), '
:message
'); } /**