From eb129f8c6c76945090fcca8aef9ddc84ba2237b4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mehmet=20Hano=C4=9Flu?= Date: Sun, 2 May 2021 15:54:11 +0300 Subject: [PATCH 1/2] Groupping support for checkbox options --- resources/views/form/checkbox.blade.php | 24 ++++++++++++++++++++++++ src/Form/Field/Checkbox.php | 17 +++++++++++++++++ 2 files changed, 41 insertions(+) diff --git a/resources/views/form/checkbox.blade.php b/resources/views/form/checkbox.blade.php index 406c8b1559..767cfe5a42 100644 --- a/resources/views/form/checkbox.blade.php +++ b/resources/views/form/checkbox.blade.php @@ -15,6 +15,28 @@ @include('admin::form.error') + @if($groups) + + @foreach($groups as $group => $options) + +

{{ $group }}

+ + @foreach($options as $option => $label) + +
+ + + +
+ + @endforeach + + @endforeach + + @else + @foreach($options as $option => $label) {!! $inline ? '' : '
' !!} @@ -27,6 +49,8 @@ @endforeach + @endif + @include('admin::form.help-block') diff --git a/src/Form/Field/Checkbox.php b/src/Form/Field/Checkbox.php index 52b8a8a323..7b60227451 100644 --- a/src/Form/Field/Checkbox.php +++ b/src/Form/Field/Checkbox.php @@ -10,6 +10,8 @@ class Checkbox extends MultipleSelect protected $canCheckAll = false; + protected $groups = null; + protected static $css = [ '/vendor/laravel-admin/AdminLTE/plugins/iCheck/all.css', ]; @@ -57,6 +59,20 @@ public function canCheckAll() return $this; } + /** + * Set chekbox groups. + * + * @param array + * + * @return $this + */ + public function groups($groups = []) + { + $this->groups = $groups; + + return $this; + } + /** * Set checked. * @@ -110,6 +126,7 @@ public function render() 'checked' => $this->checked, 'inline' => $this->inline, 'canCheckAll' => $this->canCheckAll, + 'groups' => $this->groups ]); if ($this->canCheckAll) { From 3fc309940fe2e826209d58118105ad5c4dc65acf Mon Sep 17 00:00:00 2001 From: jxlwqq Date: Mon, 3 May 2021 21:51:42 +0800 Subject: [PATCH 2/2] Update src/Form/Field/Checkbox.php --- src/Form/Field/Checkbox.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Form/Field/Checkbox.php b/src/Form/Field/Checkbox.php index 7b60227451..f6358761da 100644 --- a/src/Form/Field/Checkbox.php +++ b/src/Form/Field/Checkbox.php @@ -126,7 +126,7 @@ public function render() 'checked' => $this->checked, 'inline' => $this->inline, 'canCheckAll' => $this->canCheckAll, - 'groups' => $this->groups + 'groups' => $this->groups, ]); if ($this->canCheckAll) {