From 53805cbca57303277af758d9193d9af4a8e417f9 Mon Sep 17 00:00:00 2001 From: Chris Thompson Date: Fri, 9 Nov 2018 09:28:22 -0500 Subject: [PATCH] Initial build. --- composer.json | 31 +++++ readme.md | 0 src/ServiceProvider.php | 33 ++++++ src/resources/views/input.php | 208 ++++++++++++++++++++++++++++++++++ 4 files changed, 272 insertions(+) create mode 100644 composer.json create mode 100644 readme.md create mode 100644 src/ServiceProvider.php create mode 100644 src/resources/views/input.php diff --git a/composer.json b/composer.json new file mode 100644 index 0000000..b7e941d --- /dev/null +++ b/composer.json @@ -0,0 +1,31 @@ +{ + "name": "christhompsontldr/collective-input", + "description": "A Laravel Collective form component for building Bootstrap 4 friendly form elements.", + "authors": [ + { + "name": "Chris Thompson", + "email": "christhompsontldr@gmail.com", + "homepage": "https://christhompsontldr.com" + } + ], + "keywords": ["laravel" , "collective", "forms", "Bootstrap"], + "support": { + "issues": "https://github.com/christhompsontldr/collective-input/issues", + "source": "https://github.com/christhompsontldr/collective-input" + }, + "minimum-stability": "dev", + "autoload": { + "psr-4": { + "Christhompsontldr\\CollectiveInput\\": "src/" + } + }, + "license": "MIT", + "type": "project", + "extra": { + "laravel": { + "providers": [ + "Christhompsontldr\\CollectiveInput\\ServiceProvider" + ] + } + } +} \ No newline at end of file diff --git a/readme.md b/readme.md new file mode 100644 index 0000000..e69de29 diff --git a/src/ServiceProvider.php b/src/ServiceProvider.php new file mode 100644 index 0000000..31ddacd --- /dev/null +++ b/src/ServiceProvider.php @@ -0,0 +1,33 @@ +{$isDisplayed})): \$__env->{$isDisplayed} = true; \$__env->startPush('{$push_name}'); ?>"; + }); + + Blade::directive('endpushonce', function ($expression) { + return 'stopPush(); endif; ?>'; + }); + + // hintpath views + $this->loadViewsFrom(realpath(__DIR__ . '/resources/views'), 'collective'); + + $this->publishes([ + realpath(__DIR__ . '/resources/views') => resource_path('views/vendor/collective'), + ]); + } +} \ No newline at end of file diff --git a/src/resources/views/input.php b/src/resources/views/input.php new file mode 100644 index 0000000..abe88a1 --- /dev/null +++ b/src/resources/views/input.php @@ -0,0 +1,208 @@ +has($dotName)) ? ' is-invalid' : ''); + + +if (in_array('required', $options)) { + $options['required'] = true; +} else { + $options['required'] = false; +} + + +$selected = null; +if (isset($options['selected'])) { + $selected = $options['selected']; + unset($options['selected']); +} +$selectOptions = []; +if (isset($options['options'])) { + $selectOptions = $options['options']; + unset($options['options']); +} +$after = ''; +if (isset($options['after'])) { + $after = $options['after']; + unset($options['after']); +} + + +$label = false; +if (isset($options['label']) && $options['label'] !== false) { + $label = $options['label']; +} elseif (!isset($options['label'])) { + $label = ucwords(str_replace('_', ' ', $name)); +} +unset($options['label']); + + +if (!isset($options['id'])) { + $options['id'] = $name; +} + +$formGroupClass = ''; +if (isset($options['form-group'])) { + if (isset($options['form-group']['class'])) { + $formGroupClass = ' ' . $options['form-group']['class']; + } + + unset($options['form-group']); +} + +if (in_array($type, ['checkbox', 'radio'])) { + $options['id'] = str_replace(['[', ']'], '', $options['id']) . $options['value']; +} + +$value = null; +if (isset($options['value'])) { + $value = old($name, $options['value']); +} + + +// switch field type to textarea for type=html +switch ($type) { + case 'html': + $fieldType = 'html'; + break; + case 'datetime': + $fieldType = 'text'; + $options['class'] .= ' datetime'; + break; + default: + $fieldType = $type; +} +?> +
+ @if ($label !== false && !in_array($type, ['checkbox', 'radio'])) + {{ Form::label($name, $label) }} + @endif + + + @if ($fieldType == 'select') + {{ Form::{$fieldType}($name, $selectOptions, $selected, $options) }} + + @elseif (in_array($type, ['checkbox', 'radio'])) +
+ {{ Form::{$fieldType}($name, $options['value'], false, $options) }} + {{ Form::label($options['id'], $label, ['class' => 'form-check-label']) }} +
+ + @elseif ($fieldType == 'address') + @php + $tmpOptions = $options; + $tmpOptions['class'] .= ' mb-1'; + @endphp + {{ Form::text('address', $value, $tmpOptions) }} + {{ Form::text('address_2', $value, $options) }} +
+
+ +
+
+ @if ($label !== false) + {{ Form::label('city', 'City') }} + @endif + {{ Form::text('city', $value, $options) }} +
+
+ @if ($label !== false) + {{ Form::label('state', 'State') }} + @endif + {{ Form::text('state', $value, $options) }} +
+
+ @if ($label !== false) + {{ Form::label('zip', 'Zip') }} + @endif + {{ Form::text('Zip', $value, $options) }} +
+
+ + @elseif($type == 'datetime') +
+ +
+
+
+
+ + @elseif(in_array($type, ['password', 'file'])) + {{ Form::{$fieldType}($name, $options) }} + + @else + {{ Form::{$fieldType}($name, $value, $options) }} + @endif + + @if ($after) + {{ $after }} + @endif + + + {!! $errors->first($dotName, ':message') !!} +
+ +@if ($type == 'html') + @pushonce('after-styles:summernote') + + @endpushonce + + @pushonce('after-scripts:summernote') + + @endpushonce + + @push('after-scripts') + + @endpush +@endif + +@if ($type == 'datetime') + @pushonce('after-styles:datetime') + + @endpushonce + + @pushonce('after-scripts:datetime') + + + + @endpushonce +@endif \ No newline at end of file