From 95c90057be4bac88c799c201da52e00623b5d53d Mon Sep 17 00:00:00 2001 From: jqh <841324345@qq.com> Date: Wed, 21 Oct 2020 18:23:41 +0800 Subject: [PATCH] fix #605 --- resources/views/form/tab.blade.php | 18 +++--------------- src/Form/Layout.php | 21 +++++++++++++++++++++ src/Form/Tab.php | 27 ++++++++++++++++++++------- 3 files changed, 44 insertions(+), 22 deletions(-) diff --git a/resources/views/form/tab.blade.php b/resources/views/form/tab.blade.php index 6e3aaa534..e84f2a54d 100755 --- a/resources/views/form/tab.blade.php +++ b/resources/views/form/tab.blade.php @@ -11,22 +11,10 @@
@foreach($tabObj->getTabs() as $tab)
- @if($rows) -
- @foreach($rows as $row) - {!! $row->render() !!} - @endforeach - - @foreach($fields as $field) - @if($field instanceof \Dcat\Admin\Form\Field\Hidden) - {!! $field->render() !!} - @endif - @endforeach -
- @elseif($layout->hasColumns()) - {!! $layout->build() !!} + @if($tab['layout']->hasColumns()) + {!! $tab['layout']->build() !!} @else - @foreach($fields as $field) + @foreach($tab['fields'] as $field) {!! $field->render() !!} @endforeach @endif diff --git a/src/Form/Layout.php b/src/Form/Layout.php index 77a59a715..8b1525bfa 100755 --- a/src/Form/Layout.php +++ b/src/Form/Layout.php @@ -157,6 +157,27 @@ public function build() return $html.'
'; } + public function getColumns() + { + return $this->columns; + } + + public function setColumns(array $columns) + { + $this->columns = $columns; + + return $this; + } + + public function reset() + { + $this->hasColumn = false; + + $this->resetCurrentFields(); + + $this->setColumns([]); + } + protected function resetCurrentFields() { $this->currentFields = []; diff --git a/src/Form/Tab.php b/src/Form/Tab.php index 995613218..b91c10f7f 100755 --- a/src/Form/Tab.php +++ b/src/Form/Tab.php @@ -24,6 +24,11 @@ class Tab */ protected $offset = 0; + /** + * @var int + */ + protected $columnOffset = 0; + /** * Tab constructor. * @@ -47,11 +52,14 @@ public function __construct($form) */ public function append($title, \Closure $content, $active = false) { - $fields = $this->collectFields($content); + call_user_func($content, $this->form); + + $fields = $this->collectFields(); + $layout = $this->collectColumnLayout(); $id = 'tab-form-'.($this->tabs->count() + 1).'-'.mt_rand(0, 9999); - $this->tabs->push(compact('id', 'title', 'fields', 'active')); + $this->tabs->push(compact('id', 'title', 'fields', 'active', 'layout')); return $this; } @@ -59,14 +67,10 @@ public function append($title, \Closure $content, $active = false) /** * Collect fields under current tab. * - * @param \Closure $content - * * @return Collection */ - protected function collectFields(\Closure $content) + protected function collectFields() { - call_user_func($content, $this->form); - $fields = clone $this->form->fields(); $all = $fields->toArray(); @@ -98,6 +102,15 @@ protected function collectFields(\Closure $content) return $fields; } + protected function collectColumnLayout() + { + $layout = clone $this->form->layout(); + + $this->form->layout()->reset(); + + return $layout; + } + /** * Get all tabs. *