Skip to content

Commit

Permalink
add: custom tab name
Browse files Browse the repository at this point in the history
  • Loading branch information
seth-shi committed Oct 20, 2023
1 parent 36c1e8d commit 3fb817e
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 4 deletions.
8 changes: 4 additions & 4 deletions resources/views/form/hasmanytab.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,14 @@
@foreach($forms as $pk => $form)
<li class="nav-item ">
<a href="#{{ $relationName . '_' . $pk }}" class="nav-link @if ($form == reset($forms)) active @endif " data-toggle="tab">
{{ $pk }} <i class="feather icon-alert-circle text-red d-none"></i>
{{ $form->getTabName() }} <i class="feather icon-alert-circle text-red d-none"></i>
</a>
<i class="close-tab feather icon-trash text-red"></i>
</li>
@endforeach

</ul>

<div class="tab-content has-many-{{$columnClass}}-forms">

@foreach($forms as $pk => $form)
Expand Down Expand Up @@ -60,7 +60,7 @@

<script>
var container = '.has-many-{{ $columnClass }}';
$(container+' > .nav').off('click', 'i.close-tab').on('click', 'i.close-tab', function(){
var $navTab = $(this).siblings('a');
var $pane = $($navTab.attr('href'));
Expand Down Expand Up @@ -101,4 +101,4 @@ function replaceNestedFormIndex(value) {
var first = $('.has-error:first').parent().attr('id');
$('li a[href="#'+first+'"]').tab('show');
}
</script>
</script>
21 changes: 21 additions & 0 deletions src/Form/NestedForm.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,8 @@ class NestedForm extends WidgetForm
*/
protected $form;

protected $tabName;

/**
* Create a new NestedForm instance.
*
Expand Down Expand Up @@ -170,6 +172,25 @@ public function getKey()
return $this->key;
}

/**
* $nestForm->setTableName($nestForm->model()->xxx);
* @param $tabName
* @return mixed
*/
public function setTabName($tabName)
{
return $this->tabName = $tabName;
}

public function getTabName()
{
if (is_null($this->tabName)) {
$this->tabName = $this->getKey();
}

return $this->tabName;
}

/**
* Set key for current form.
*
Expand Down

0 comments on commit 3fb817e

Please sign in to comment.