How to keep the tab active after a submit?

0

I am programming a site with the CODE IGNITER framework and a view has a tab-pane. By entering the information to the form and reloading the view, I am in the first tab and I need to be able to handle that

Any suggestions or ideas?

This is the code of the view

<ul class="nav nav-tabs">
    <li class="active">
        <a href="#a" data-toggle="tab">Correo</a>
    </li>
    <li>
        <a href="#b" data-toggle="tab">Usuarios</a>
    </li>
    <li>
        <a href="#c" data-toggle="tab">Clientes</a>
    </li>
    <li>
        <a href="#d" data-toggle="tab">Embarques</a>
    </li>
</ul>
...
<div class="tab-pane active" id="b">
    <form class="form-group">
        ...
    </form>
</div>

Then in my controller I have

public function nuevoUsuario(){
    $this->form_validation->set_error_delimiters('<div class="error">', '</div>');
    $this->form_validation->set_rules('correoUser', 'Correo', 'required|valid_email');
    $this->form_validation->set_rules('nUsuario', 'Nombre Usuario', 'required|min_length[5]|max_length[50]');

    if ($this->form_validation->run() == FALSE) {
        $data['message'] = validation_errors();
        $this->load->view('Configuracion/config_view',$data);
    }
    else {
        $data = array(
            'usuario' => $this->input->post('correoUser'),
            'nombre' => $this->input->post('nUsuario'),
            'password' => $this->input->post('passUser'),
            'id_perfil' => $this->input->post('perfil')

        );
        $this->Config_model->insertUser($data);
        $data['message'] = 'Datos Ingresados con Exito';
        $this->load->view('Configuracion/config_view', $data);
    }
}

I would like that when loading the view, it remains in tab #b but I do not know how to handle that event

    
asked by Gonzalo Oyarce 16.05.2017 в 17:26
source

1 answer

0

There may be two possible paths

1) Make a call AJAX to your function of the forms and so do not reload the view. With this the tab that was active will remain as such. In Ajax once you receive a response type (whether it is correct or with some code error, database or restriction of your own logic) you can handle it without problem.

2) The other is to IDENTIFY which tab was active.

var tabActiva = null;
$('a[data-toggle="tab"]').on('shown', function (e) {
  tabActiva = e.target;
})

So you can handle it once you come back from POST.

    
answered by 18.05.2017 / 23:15
source