Within the form
have a field of the type hidden
who 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 event tab
($('#myTabs a').click(function (e)
), passes the value of tab
selected for the field hidden
tabSelected
($('#tabSelected').val(e.target.hash);
).
Within the div
and ul
of that tab
in class
has a code that will be generated the value active
giving the selection of the last tab
which has been chosen (if it is the first time, the first time tab
is selected by pattern), watch closely at the code html
.
So far only changes in the part of View
, has a server request part that is demonstrated in these two routes, the first is the normal load, without saving any information or at least some kind of request, the other receives a request and returns to View
the last tab
selectioanda:
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 designed, can test and observe the behavior and make the appropriate changes to your code, any doubt just ask
You can store the information in a field
hidden
and all clicks change the value in that fieldhidden
, when making a request compare which item is to be with that classactive
. This tab is bootstrap?– novic
Yes, Virgilio, I’m using the same bootstrap tab.
– Jonatas Dutka