Skip to content

Commit

Permalink
Set bootstrap 4 as default
Browse files Browse the repository at this point in the history
  • Loading branch information
rdehnhardt committed Jun 11, 2018
1 parent 85ca14f commit 3ad4c5e
Showing 1 changed file with 28 additions and 38 deletions.
66 changes: 28 additions & 38 deletions src/FormBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 '<div' . $this->html->attributes($options) . '>' . $label;
Expand Down Expand Up @@ -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);
}

Expand All @@ -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);
}

/**
Expand Down Expand Up @@ -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);
Expand All @@ -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);
Expand All @@ -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);
Expand All @@ -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);
Expand All @@ -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);
}

Expand Down Expand Up @@ -330,7 +320,7 @@ private function getFormattedErrors($name)

$errors = $this->session->get('errors');

return $errors->first($this->transformKey($name), '<p class="help-block">:message</p>');
return $errors->first($this->transformKey($name), '<div class="invalid-feedback">:message</div>');
}

/**
Expand Down

0 comments on commit 3ad4c5e

Please sign in to comment.