Within form
has a field of type hidden
which is responsible for storing the last tab
selected, in this example the name is tabSelected
,
<form action="/tabpost" method="post">
<input type="hidden" name="_token" id="token" value="{{ csrf_token() }}">
<input type="hidden" id="tabSelected" name="tabSelected" value="{{isset($tabSelected)?$tabSelected:'#home'}}" />
<div id="myTabs">
<ul class="nav nav-tabs">
<li role="presentation" class="{{isset($tabSelected)&&$tabSelected==='#home'?'active':!isset($tabSelected)?'active':''}}"><a href="#home">Home</a></li>
<li role="presentation" class="{{isset($tabSelected)&&$tabSelected==='#profile'?'active':''}}"><a href="#profile">Profile</a></li>
<li role="presentation" class="{{isset($tabSelected)&&$tabSelected==='#messages'?'active':''}}"><a href="#messages">Messages</a></li>
</ul>
<div class="tab-content">
<div role="tabpanel" class="tab-pane{{isset($tabSelected)&&$tabSelected==='#home'?' active':!isset($tabSelected)?' active':''}}" id="home">home</div>
<div role="tabpanel" class="tab-pane{{isset($tabSelected)&&$tabSelected==='#profile'?' active':''}}" id="profile">profile</div>
<div role="tabpanel" class="tab-pane{{isset($tabSelected)&&$tabSelected==='#messages'?' active':''}}" id="messages">messages</div>
</div>
</div>
<button>Enviar</button>
</form>
<script>
$('#myTabs a').click(function (e) {
$(this).tab('show');
$('#tabSelected').val(e.target.hash);
e.preventDefault();
});
</script>
and in the click event of tab
( $('#myTabs a').click(function (e)
), it passes the value of the tab
selected to the field hidden
tabSelected
( $('#tabSelected').val(e.target.hash);
).
Within the div
and ul
of this tab
in the class
has a code that will generate the value active
giving the selection of the last tab
that was chosen (if it is the first time, the first tab
is selected by default ), notice an attack on html
.
So far it's only changes in the
View
part, there is a server request part that is demonstrated in these two routes, the first one is the normal loading, without saving any information or at least some type of request, already the another receives a request and returns to
View
the last
tab
select:
Route::get('tab', function()
{
return view('tab');
});
Route::post('tabpost', function(Request $request)
{
$data['tabSelected'] = $request->get('tabSelected');
return view('tab', $data);
});
This is a functional example, which I have done, can test and observe the behavior and make the changes in your code, any questions just ask