diff --git a/composer.json b/composer.json index b25e8d0..f8dae32 100644 --- a/composer.json +++ b/composer.json @@ -1,5 +1,5 @@ { - "name": "netojose/laravel-bootstrap-4-forms", + "name": "zitsky/laravel-bootstrap-4-forms", "type": "package", "description": "Bootstrap 4 form builder for Laravel 5", "keywords": [ diff --git a/src/FormBuilder.php b/src/FormBuilder.php index 5ad8523..8c44e65 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 = '
'; } - 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')); @@ -151,11 +151,14 @@ private function renderSelect(): string } $attributes = $this->getInputAttributes(); + if(isset($attributes['multiple'])) { + $attributes['name'] .= "[]"; + } $attrs = $this->buildHtmlAttrs($attributes); return $this->wrapperInput(''); } - private function renderTextarea(): string + protected function renderTextarea(): string { $attributes = $this->getInputAttributes(); $value = $attributes['value']; @@ -164,21 +167,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 +189,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 +197,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 +209,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')); @@ -263,6 +266,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; @@ -281,7 +285,7 @@ private function getInputAttributes(): array ]); } - private function renderLabel(): string + protected function renderLabel(): string { extract($this->get('label', 'formInline', 'render')); @@ -298,7 +302,7 @@ private function renderLabel(): string return ''; } - private function getText($key) + protected function getText($key) { extract($this->get('formLocale')); if ($formLocale) { @@ -307,7 +311,7 @@ private function getText($key) return $key; } - private function resetAttributes($resetAll = false) + protected function resetAttributes($resetAll = false) { // Remove all attributes if ($resetAll) { @@ -321,7 +325,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')); @@ -343,7 +347,7 @@ private function wrapperInput(string $input): string return '