From 6740bfb60c293670d81818014dd162b1aa75ec68 Mon Sep 17 00:00:00 2001 From: kaziu687 Date: Mon, 16 Sep 2019 10:30:19 +0200 Subject: [PATCH 1/6] Update FormBuilder.php --- src/FormBuilder.php | 1 + 1 file changed, 1 insertion(+) diff --git a/src/FormBuilder.php b/src/FormBuilder.php index 5ad8523..1ea8923 100644 --- a/src/FormBuilder.php +++ b/src/FormBuilder.php @@ -263,6 +263,7 @@ private function getInputAttributes(): array if ($this->hasOldInput()) { $isChecked = old($name) === $value; } else { + $value = $value === 'on' ? true : false; $isChecked = isset($formData[$name]) ? $formData[$name] === $value : $checked; } $attributes['checked'] = $isChecked; From 01748799ae3bb6e4babe905c123f3cf8cb6f1c02 Mon Sep 17 00:00:00 2001 From: Remik Date: Mon, 21 Oct 2019 11:01:47 +0200 Subject: [PATCH 2/6] Private functions to protected --- src/FormBuilder.php | 62 ++++++++++++++++++++++----------------------- 1 file changed, 31 insertions(+), 31 deletions(-) diff --git a/src/FormBuilder.php b/src/FormBuilder.php index 1ea8923..55cdd90 100644 --- a/src/FormBuilder.php +++ b/src/FormBuilder.php @@ -18,12 +18,12 @@ public function set($key, $value) $this->attrs[$key] = $value; } - private function formatMethod($value) + protected function formatMethod($value) { return strtolower($value); } - private function formatFormData($value) + protected function formatFormData($value) { if (is_object($value) && method_exists($value, 'toArray')) { return $value->toArray(); @@ -31,7 +31,7 @@ private function formatFormData($value) return $value; } - private function formatOptions($value) + protected function formatOptions($value) { extract($this->get('optionIdKey', 'optionValueKey')); @@ -58,7 +58,7 @@ public function render(): string return $output; } - private function renderFormOpen(): string + protected function renderFormOpen(): string { extract($this->get('id', 'method', 'url', 'formMultipart', 'formInline', 'autocomplete')); @@ -89,13 +89,13 @@ private function renderFormOpen(): string return $output; } - private function renderFormClose(): string + protected function renderFormClose(): string { $this->resetAttributes(true); return ''; } - private function renderFieldsetOpen(): string + protected function renderFieldsetOpen(): string { $output = '
'; extract($this->get('legend')); @@ -107,12 +107,12 @@ private function renderFieldsetOpen(): string return $output; } - private function renderFieldsetClose(): string + protected function renderFieldsetClose(): string { return '
'; } - private function renderErrors(): string + protected function renderErrors(): string { $errors = $this->errors()->all(); if (count($errors) < 1) { @@ -131,14 +131,14 @@ private function renderErrors(): string return $output . ''; } - private function renderInput(): string + protected function renderInput(): string { $attributes = $this->getInputAttributes(); $attrs = $this->buildHtmlAttrs($attributes); return $this->wrapperInput(''); } - private function renderSelect(): string + protected function renderSelect(): string { extract($this->get('options')); @@ -155,7 +155,7 @@ private function renderSelect(): string return $this->wrapperInput(''); } - private function renderTextarea(): string + protected function renderTextarea(): string { $attributes = $this->getInputAttributes(); $value = $attributes['value']; @@ -164,21 +164,21 @@ private function renderTextarea(): string return $this->wrapperInput(''); } - private function renderCheckbox(): string + protected function renderCheckbox(): string { $attributes = $this->getInputAttributes(); $attrs = $this->buildHtmlAttrs($attributes); return $this->wrapperRadioCheckbox(''); } - private function renderRadio(): string + protected function renderRadio(): string { $attributes = $this->getInputAttributes(); $attrs = $this->buildHtmlAttrs($attributes); return $this->wrapperRadioCheckbox(''); } - private function renderAnchor(): string + protected function renderAnchor(): string { extract($this->get('url', 'value')); $class = $this->getBtnAnchorClasses(); @@ -186,7 +186,7 @@ private function renderAnchor(): string return '' . $value . ''; } - private function renderButton(): string + protected function renderButton(): string { extract($this->get('type', 'value', 'disabled')); $class = $this->getBtnAnchorClasses(); @@ -194,7 +194,7 @@ private function renderButton(): string return ''; } - private function getBtnAnchorClasses() + protected function getBtnAnchorClasses() { extract($this->get('size', 'color', 'outline', 'block', 'type', 'value', 'formInline')); return $this->createAttrsList( @@ -206,13 +206,13 @@ private function getBtnAnchorClasses() ); } - private function isRadioOrCheckbox(): bool + protected function isRadioOrCheckbox(): bool { extract($this->get('render')); return in_array($render, ['checkbox', 'radio']); } - private function getInputAttributes(): array + protected function getInputAttributes(): array { extract($this->get('render', 'type', 'multiple', 'name', 'size', 'placeholder', 'help', 'disabled', 'readonly', 'required', 'autocomplete', 'min', 'max', 'value', 'checked', 'formData', 'disableValidation')); @@ -282,7 +282,7 @@ private function getInputAttributes(): array ]); } - private function renderLabel(): string + protected function renderLabel(): string { extract($this->get('label', 'formInline', 'render')); @@ -299,7 +299,7 @@ private function renderLabel(): string return ''; } - private function getText($key) + protected function getText($key) { extract($this->get('formLocale')); if ($formLocale) { @@ -308,7 +308,7 @@ private function getText($key) return $key; } - private function resetAttributes($resetAll = false) + protected function resetAttributes($resetAll = false) { // Remove all attributes if ($resetAll) { @@ -322,7 +322,7 @@ private function resetAttributes($resetAll = false) }, ARRAY_FILTER_USE_KEY); } - private function wrapperInput(string $input): string + protected function wrapperInput(string $input): string { extract($this->get('type', 'help', 'wrapperAttrs', 'formInline', 'name')); @@ -344,7 +344,7 @@ private function wrapperInput(string $input): string return '
' . $label . $input . $helpText . $error . '
'; } - private function wrapperRadioCheckbox(string $input): string + protected function wrapperRadioCheckbox(string $input): string { extract($this->get('inline', 'name', 'wrapperAttrs')); @@ -360,7 +360,7 @@ private function wrapperRadioCheckbox(string $input): string return '
' . $input . $label . $error . '
'; } - private function getInputErrorMarkup(string $name): string + protected function getInputErrorMarkup(string $name): string { extract($this->get('disableValidation')); @@ -375,7 +375,7 @@ private function getInputErrorMarkup(string $name): string return '
' . $this->errors()->first($name) . '
'; } - private function getId() + protected function getId() { extract($this->get('id', 'name', 'formIdPrefix', 'render', 'value')); @@ -386,12 +386,12 @@ private function getId() return ($formIdPrefix ?? 'inp-') . $name . ($render === 'radio' ? '-' . $value : ''); } - private function hasOldInput() + protected function hasOldInput() { return count((array) old()) != 0; } - private function getValue() + protected function getValue() { extract($this->get('name', 'value', 'formData')); if ($this->isRadioOrCheckbox()) { @@ -407,7 +407,7 @@ private function getValue() return $value ?? $fromFill; } - private function buildHtmlAttrs(array $attributes, $appendAttrs = true): string + protected function buildHtmlAttrs(array $attributes, $appendAttrs = true): string { if ($appendAttrs) { @@ -433,7 +433,7 @@ private function buildHtmlAttrs(array $attributes, $appendAttrs = true): string )); } - private function createAttrsList(...$items) + protected function createAttrsList(...$items) { $attrs = []; foreach ($items as $item) { @@ -445,7 +445,7 @@ private function createAttrsList(...$items) return join(' ', array_filter($attrs)); } - private function errors() + protected function errors() { $errors = session('errors', app(ViewErrorBag::class)); extract($this->get('formErrorBag')); @@ -455,7 +455,7 @@ private function errors() return $errors; } - private function get(...$keys): array + protected function get(...$keys): array { $return = []; foreach ($keys as $key) { From ceb94d1a14778be694afac80882762584f8bb333 Mon Sep 17 00:00:00 2001 From: Remik Date: Mon, 21 Oct 2019 11:06:54 +0200 Subject: [PATCH 3/6] Updated package name --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index b25e8d0..a1d112b 100644 --- a/composer.json +++ b/composer.json @@ -1,5 +1,5 @@ { - "name": "netojose/laravel-bootstrap-4-forms", + "name": "kaziu687/laravel-bootstrap-4-forms", "type": "package", "description": "Bootstrap 4 form builder for Laravel 5", "keywords": [ From bfa21af20e98faaf9863c95a56bc20a12f207f64 Mon Sep 17 00:00:00 2001 From: Kirill Date: Sat, 2 May 2020 16:01:23 +0300 Subject: [PATCH 4/6] Clean name for multiple select old value --- src/FormBuilder.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/FormBuilder.php b/src/FormBuilder.php index 55cdd90..a278337 100644 --- a/src/FormBuilder.php +++ b/src/FormBuilder.php @@ -399,7 +399,7 @@ protected function getValue() } if ($this->hasOldInput()) { - return old($name, $value); + return old(preg_replace("/\\[\\]/mui","",$name), $value); } $fromFill = $formData[$name] ?? null; From 260b08c1b288a4fa24f20a4bd669105576bc79e3 Mon Sep 17 00:00:00 2001 From: Kirill Grodzitskiy Date: Sat, 2 May 2020 18:01:45 +0300 Subject: [PATCH 5/6] Update composer.json --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index a1d112b..f8dae32 100644 --- a/composer.json +++ b/composer.json @@ -1,5 +1,5 @@ { - "name": "kaziu687/laravel-bootstrap-4-forms", + "name": "zitsky/laravel-bootstrap-4-forms", "type": "package", "description": "Bootstrap 4 form builder for Laravel 5", "keywords": [ From ffe5c0cbb562b10efd00125e42beac2cd2a0377d Mon Sep 17 00:00:00 2001 From: Kirill Date: Sat, 2 May 2020 19:53:32 +0300 Subject: [PATCH 6/6] fix multiple name for handle validation errors --- src/FormBuilder.php | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/FormBuilder.php b/src/FormBuilder.php index a278337..8c44e65 100644 --- a/src/FormBuilder.php +++ b/src/FormBuilder.php @@ -151,6 +151,9 @@ protected function renderSelect(): string } $attributes = $this->getInputAttributes(); + if(isset($attributes['multiple'])) { + $attributes['name'] .= "[]"; + } $attrs = $this->buildHtmlAttrs($attributes); return $this->wrapperInput(''); }