K
K
kindpirate2018-08-17 21:08:27
JavaScript
kindpirate, 2018-08-17 21:08:27

How to open a modal window in a specific tab after the page is loaded?

There is a modal window and the following links leading to different tabs of the modal window:

<a href="#autorizeTab" class="btn btn-warm" data-toggle="modal" data-target="#generalModal">Войти</a>
<a href="#registerTab" class="btn btn-warm" data-toggle="modal" data-target="#generalModal">Регистрация</
<div class="modal" id="generalModal">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-body">
                <div role="tabpanel">
                     <ul class="nav nav-tabs" id="referenceTab">
                        <li class="nav-item">
                            <a class="nav-link active" href="#autorizeTab" data-toggle="tab">Вход</a>
                        </li>
                        <li class="nav-item">
                            <a class="nav-link" href="#registerTab" data-toggle="tab">Регистрация</a>
                        </li>
                    </ul>
                    <div class="tab-content">
                        <div role="tabpanel" class="tab-pane show active" id="autorizeTab">
                            @include('layouts.components.modalComponents.autorizeModal')// строка для шаблонизатора
                        </div>
                        <div role="tabpanel" class="tab-pane" id="registerTab">
                            @include('layouts.components.modalComponents.registerModal')// строка для шаблонизатора
                        </div>
                    </div> 
                </div>
            </div>
        </div>
    </div>
</div>


it is necessary that when the page loads, depending on whether there are data validation errors, a certain tab opens:
$(document).ready(function() {
@if($errors->has('reg_error'))// строка для шаблонизатора
$('.nav-tabs a[href="#registerTab"]').tab('show');
@elseif($errors->has('auth_error'))// строка для шаблонизатора
$('.nav-tabs a[href="#autorizeTab"]').tab('show');
@endif// строка для шаблонизатора
});


But this code doesn't work. What are the solutions to this problem? Used by Boostrap 4

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Anton Shamanov, 2018-10-04
@SilenceOfWinter

well, then you switch tabs, but where do you actually have $('#generalModal').modal('show') ?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question