After adding / deleting my active tab-panel (Laravel)

0

I am developing an application where it is possible to include services in tab-panel and in the other tab-panel it is possible to save other information, however when saving the registry in tab-panel services, view returns again to the main tab. I know the reason is because of the active class in my tab-panel link, but how do I set the asset after using create:: or ->delete of Laravel 5.3 ?

Below is an example of my application.

<ulclass="nav nav-tabs">
    <li class="active">
        <a data-toggle="tab" href="#detalhes">Detalhes da OS</a>
    </li>
    <li class="">
        <a data-toggle="tab" href="#servicos">Serviços</a>
    </li>
</ul>
    
asked by anonymous 03.11.2016 / 21:26

1 answer

0

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

    
05.11.2016 / 15:48