Skip to content

Commit bc15b25

Browse files
authored
Merge pull request #5272 from Laravel-Backpack/use-tab-index-when-we-cant-parse-the-name
use tab index when slug cant be generated
2 parents 9980a79 + bbff396 commit bc15b25

File tree

2 files changed

+34
-10
lines changed

2 files changed

+34
-10
lines changed

src/resources/views/crud/inc/show_tabbed_fields.blade.php

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -30,13 +30,19 @@
3030
<div class="nav-tabs-custom {{ $horizontalTabs ? '' : 'row'}}" id="form_tabs">
3131
<ul class="nav {{ $horizontalTabs ? 'nav-tabs' : 'flex-column nav-pills'}} {{ $horizontalTabs ? '' : 'col-md-3' }}" role="tablist">
3232
@foreach ($crud->getTabs() as $k => $tab)
33+
@php
34+
$tabSlug = Str::slug($tab);
35+
if(empty($tabSlug)) {
36+
$tabSlug = $k;
37+
}
38+
@endphp
3339
<li role="presentation" class="nav-item">
34-
<a href="#tab_{{ Str::slug($tab) }}"
35-
aria-controls="tab_{{ Str::slug($tab) }}"
40+
<a href="#tab_{{ $tabSlug }}"
41+
aria-controls="tab_{{ $tabSlug }}"
3642
role="tab"
3743
data-toggle="tab" {{-- tab indicator for Bootstrap v4 --}}
38-
tab_name="{{ Str::slug($tab) }}" {{-- tab name for Bootstrap v4 --}}
39-
data-name="{{ Str::slug($tab) }}" {{-- tab name for Bootstrap v5 --}}
44+
tab_name="{{ $tabSlug }}" {{-- tab name for Bootstrap v4 --}}
45+
data-name="{{ $tabSlug }}" {{-- tab name for Bootstrap v5 --}}
4046
data-bs-toggle="tab" {{-- tab name for Bootstrap v5 --}}
4147
class="nav-link text-decoration-none {{ isset($tabWithError) && $tabWithError ? ($tab == $tabWithError ? 'active' : '') : ($k == 0 ? 'active' : '') }}"
4248
>{{ $tab }}</a>
@@ -47,7 +53,13 @@ class="nav-link text-decoration-none {{ isset($tabWithError) && $tabWithError ?
4753
<div class="tab-content {{$horizontalTabs ? '' : 'col-md-9'}}">
4854

4955
@foreach ($crud->getTabs() as $k => $tabLabel)
50-
<div role="tabpanel" class="tab-pane {{ isset($tabWithError) && $tabWithError ? ($tabLabel == $tabWithError ? ' active' : '') : ($k == 0 ? ' active' : '') }}" id="tab_{{ Str::slug($tabLabel) }}">
56+
@php
57+
$tabSlug = Str::slug($tabLabel);
58+
if(empty($tabSlug)) {
59+
$tabSlug = $k;
60+
}
61+
@endphp
62+
<div role="tabpanel" class="tab-pane {{ isset($tabWithError) && $tabWithError ? ($tabLabel == $tabWithError ? ' active' : '') : ($k == 0 ? ' active' : '') }}" id="tab_{{ $tabSlug }}">
5163

5264
<div class="row">
5365
@include('crud::inc.show_fields', ['fields' => $crud->getTabItems($tabLabel, 'fields')])

src/resources/views/crud/inc/show_tabbed_table.blade.php

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,19 @@
1717
<div class="nav-tabs-custom {{ $horizontalTabs ? '' : 'row'}}" id="form_tabs">
1818
<ul class="nav {{ $horizontalTabs ? 'nav-tabs' : 'flex-column nav-pills'}} {{ $horizontalTabs ? '' : 'col-md-3' }}" role="tablist">
1919
@foreach ($columnsWithTabs as $k => $tabLabel)
20+
@php
21+
$tabSlug = Str::slug($tabLabel);
22+
if(empty($tabSlug)) {
23+
$tabSlug = $k;
24+
}
25+
@endphp
2026
<li role="presentation" class="nav-item">
21-
<a href="#tab_{{ Str::slug($tabLabel) }}"
22-
aria-controls="tab_{{ Str::slug($tabLabel) }}"
27+
<a href="#tab_{{ $tabSlug }}"
28+
aria-controls="tab_{{ $tabSlug }}"
2329
role="tab"
2430
data-toggle="tab" {{-- tab indicator for Bootstrap v4 --}}
25-
tab_name="{{ Str::slug($tabLabel) }}" {{-- tab name for Bootstrap v4 --}}
26-
data-name="{{ Str::slug($tabLabel) }}" {{-- tab name for Bootstrap v5 --}}
31+
tab_name="{{ $tabSlug }}" {{-- tab name for Bootstrap v4 --}}
32+
data-name="{{ $tabSlug }}" {{-- tab name for Bootstrap v5 --}}
2733
data-bs-toggle="tab" {{-- tab name for Bootstrap v5 --}}
2834
class="nav-link {{ $k === 0 ? 'active' : '' }}"
2935
>{{ $tabLabel }}</a>
@@ -33,7 +39,13 @@ class="nav-link {{ $k === 0 ? 'active' : '' }}"
3339

3440
<div class="tab-content p-0 {{ $horizontalTabs ? '' : 'col-md-9' }}">
3541
@foreach ($columnsWithTabs as $k => $tabLabel)
36-
<div role="tabpanel" class="tab-pane p-0 border-none {{ $k === 0 ? 'active' : '' }}" id="tab_{{ Str::slug($tabLabel) }}">
42+
@php
43+
$tabSlug = Str::slug($tabLabel);
44+
if(empty($tabSlug)) {
45+
$tabSlug = $k;
46+
}
47+
@endphp
48+
<div role="tabpanel" class="tab-pane p-0 border-none {{ $k === 0 ? 'active' : '' }}" id="tab_{{ $tabSlug }}">
3749
@include('crud::inc.show_table', ['columns' => $crud->getTabItems($tabLabel, 'columns'), 'displayActionsColumn' => false])
3850
</div>
3951
@endforeach

0 commit comments

Comments
 (0)