Skip to content

Commit

Permalink
Add random part in tab names (#5260)
Browse files Browse the repository at this point in the history
Fixes bootstrap js tab toggle not workinging when
clicking add button more than 2 times
  • Loading branch information
Wang Chao authored and greg0ire committed Apr 17, 2019
1 parent b235391 commit 53f0390
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 8 deletions.
13 changes: 9 additions & 4 deletions src/Resources/views/CRUD/base_edit_form.html.twig
Expand Up @@ -32,11 +32,13 @@

<div class="col-md-12">
{% if has_tab %}
{% set tab_prefix = 'tab_' ~ admin.uniqid ~ '_' ~ random() %}
{% set tab_query_index = app.request.query.get('_tab', 0)|split("_")|last %}
<div class="nav-tabs-custom">
<ul class="nav nav-tabs" role="tablist">
{% for name, form_tab in admin.formtabs %}
{% set _tab_name = 'tab_'~admin.uniqid~'_'~loop.index %}
<li{% if (not app.request.query.has('_tab') and loop.index == 1) or (app.request.query.get('_tab') == _tab_name) %} class="active"{% endif %}>
{% set _tab_name = tab_prefix ~ '_' ~ loop.index %}
<li{% if (not app.request.query.has('_tab') and loop.index == 1) or (tab_query_index == loop.index) %} class="active"{% endif %}>
<a href="#{{ _tab_name }}" class="changer-tab" aria-controls="{{ _tab_name }}" data-toggle="tab">
<i class="fa fa-exclamation-circle has-errors hide" aria-hidden="true"></i> {{ form_tab.label|trans({}, form_tab.translation_domain ?: admin.translationDomain) }}
</a>
Expand All @@ -45,8 +47,11 @@
</ul>
<div class="tab-content">
{% for code, form_tab in admin.formtabs %}
{% set _tab_name = 'tab_'~admin.uniqid~'_'~loop.index %}
<div class="tab-pane fade{% if (not app.request.query.has('_tab') and loop.first) or (app.request.query.get('_tab') == _tab_name) %} in active{% endif %}" id="{{ _tab_name }}">
{% set _tab_name = tab_prefix ~ loop.index %}
<div
class="tab-pane fade{% if (not app.request.query.has('_tab') and loop.first) or (tab_query_index == loop.index) %} in active{% endif %}"
id="{{ _tab_name }}"
>
<div class="box-body container-fluid">
<div class="sonata-ba-collapsed-fields">
{% if form_tab.description != false %}
Expand Down
10 changes: 6 additions & 4 deletions src/Resources/views/CRUD/base_show.html.twig
Expand Up @@ -38,11 +38,13 @@ file that was distributed with this source code.
{% set has_tab = (admin.showtabs|length == 1 and admin.showtabs|keys[0] != 'default') or admin.showtabs|length > 1 %}

{% if has_tab %}
{% set tab_prefix = 'tab_' ~ admin.uniqid ~ '_' ~ random() %}
{% set tab_query_index = app.request.query.get('_tab', 0)|split("_")|last %}
<div class="nav-tabs-custom">
<ul class="nav nav-tabs" role="tablist">
{% for name, show_tab in admin.showtabs %}
{% set _tab_name = 'tab_'~admin.uniqid~'_'~loop.index %}
<li{% if (not app.request.query.has('_tab') and loop.index == 1) or (app.request.query.get('_tab') == _tab_name) %} class="active"{% endif %}>
{% set _tab_name = tab_prefix ~ '_' ~ loop.index %}
<li{% if (not app.request.query.has('_tab') and loop.index == 1) or (tab_query_index == loop.index) %} class="active"{% endif %}>
<a href="#{{ _tab_name }}" class="changer-tab" aria-controls="{{ _tab_name }}" data-toggle="tab">
{{ show_tab.label|trans({}, show_tab.translation_domain ?: admin.translationDomain) }}
</a>
Expand All @@ -52,9 +54,9 @@ file that was distributed with this source code.

<div class="tab-content">
{% for code, show_tab in admin.showtabs %}
{% set _tab_name = 'tab_'~admin.uniqid~'_'~loop.index %}
{% set _tab_name = tab_prefix ~ '_' ~ loop.index %}
<div
class="tab-pane fade{% if (not app.request.query.has('_tab') and loop.first) or (app.request.query.get('_tab') == _tab_name) %} in active{% endif %}"
class="tab-pane fade{% if (not app.request.query.has('_tab') and loop.first) or (tab_query_index == loop.index) %} in active{% endif %}"
id="{{ _tab_name }}"
>
<div class="box-body container-fluid">
Expand Down

0 comments on commit 53f0390

Please sign in to comment.