Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/hasmany tab name #2080

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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>
2 changes: 1 addition & 1 deletion src/Form/Field.php
Original file line number Diff line number Diff line change
Expand Up @@ -330,7 +330,7 @@ protected function formatFieldData($data)
$value = [];

foreach ($this->column as $key => $column) {
$value[$key] = $this->getValueFromData($data, $this->normalizeColumn($column));
$value[$key] = $this->getValueFromData($data, $this->normalizeColumn($column), data_get($this->value, $key));
}

return $value;
Expand Down
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