Skip to content

Commit

Permalink
fix #605
Browse files Browse the repository at this point in the history
  • Loading branch information
jqhph committed Oct 21, 2020
1 parent f29205f commit 95c9005
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 22 deletions.
18 changes: 3 additions & 15 deletions resources/views/form/tab.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,22 +11,10 @@
<div class="tab-content fields-group mt-2 pt-1 pb-1">
@foreach($tabObj->getTabs() as $tab)
<div class="tab-pane {{ $tab['active'] ? 'active' : '' }}" id="{{ $tab['id'] }}">
@if($rows)
<div class="ml-2 mb-2" style="margin-top: -1rem">
@foreach($rows as $row)
{!! $row->render() !!}
@endforeach

@foreach($fields as $field)
@if($field instanceof \Dcat\Admin\Form\Field\Hidden)
{!! $field->render() !!}
@endif
@endforeach
</div>
@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
Expand Down
21 changes: 21 additions & 0 deletions src/Form/Layout.php
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,27 @@ public function build()
return $html.'</div>';
}

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 = [];
Expand Down
27 changes: 20 additions & 7 deletions src/Form/Tab.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,11 @@ class Tab
*/
protected $offset = 0;

/**
* @var int
*/
protected $columnOffset = 0;

/**
* Tab constructor.
*
Expand All @@ -47,26 +52,25 @@ 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;
}

/**
* 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();
Expand Down Expand Up @@ -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.
*
Expand Down

0 comments on commit 95c9005

Please sign in to comment.