Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Modal within other modal on UIkit

When I'm clicking on the second modal, the first modal disappears. However, I want to keep it open as well! Is this a way to disable that behavior?

I have also noticed that other frameworks such as Foundation have the same behavior.

Here's my code:

<a href="#my-id" data-uk-modal>Open Modal</a>
<div id="my-id" class="uk-modal">
    <div class="uk-modal-dialog"> 
        <a class="uk-modal-close uk-close"></a>
        <p>Lorem ipsum...</p> 
        <a href="#my-id2" data-uk-modal>Nested Modal</a>
    </div>
</div>
<div id="my-id2" class="uk-modal">
    <div class="uk-modal-dialog"> 
        <a class="uk-modal-close uk-close"></a>
        <p>Lorem ipsum...</p>
    </div>
</div>

See the jsfiddle demo.

like image 312
fmuser Avatar asked Jul 01 '15 11:07

fmuser


3 Answers

You can show multiple Modals using uk-modal="stack: true"

Here is the code

<button class="uk-button uk-button-default uk-margin-small-right" type="button" data-uk-toggle="target: #modal-example-1">Open</button>

<!-- This is the Parent modal -->
<div id="modal-example-1" uk-modal>
    <div class="uk-modal-dialog uk-modal-body">
        <h2 class="uk-modal-title">Parent Modal</h2>
        <p>Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.</p>
        <p class="uk-text-right">
            <button class="uk-button uk-button-default uk-modal-close" type="button">Cancel</button>
            <button class="uk-button uk-button-primary" type="button">Save</button>
        </p>
        <button class="uk-button uk-button-default uk-margin-small-right" type="button" data-uk-toggle="target: #modal-example-2">Open</button>
    </div>
</div>

<!-- This is the Child modal -->
<div id="modal-example-2" uk-modal="stack: true">
    <div class="uk-modal-dialog uk-modal-body">
        <h2 class="uk-modal-title">Child Modal</h2>
        <p>Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.</p>
    </div>
</div>
like image 154
FarazShuja Avatar answered Nov 01 '22 19:11

FarazShuja


From documentation:

You can trigger a new modal inside the current modal. The default behaviour closes the first modal when a second one opens. You can prevent this from happening by adding the data-uk-modal="{target:'#ID',modal:false}" attribute.

So something like:

<div>
    <h2>Multiple Modal</h2>
    <button class="uk-button" data-uk-modal="{target:'#modal1', modal: false}">Open Modal 1</button>

</div>

<!-- This is the modal 1-->
<div id="modal1" class="uk-modal">
    <div class="uk-modal-dialog">
        <h2>Modal 1</h2>
        <button class="uk-button" data-uk-modal="{target:'#modal2', modal: false}">Open Modal 2</button>      
    </div>
</div>


<!-- This is the modal 2-->
<div id="modal2" class="uk-modal">
    <div class="uk-modal-dialog">
        <h2>Modal 2</h2>
        <a class="uk-modal-close" href="#">Close Modal 2</a>
    </div>
</div>

should work.

I have it working with javascript:

var modal1 = UIkit.modal("#modal1", {center: true, modal: false}),
    modal2 = UIkit.modal("#modal2", {modal: false});
like image 24
Jorge Avatar answered Nov 01 '22 19:11

Jorge


You have do some changes :

Your HTML code :

<a href="#my-id" data-uk-modal >Open Modal</a>
<div id="my-id" class="uk-modal">
    <div class="uk-modal-dialog"> 
        <a class="uk-modal-close uk-close"></a>
        <p>Lorem ipsum...</p> 
        <a href="#my-id2" data-uk-modal>Nested Modal</a>
    </div>
</div>
<div id="my-id2" class="uk-modal">
    <div class="uk-modal-dialog"> 
        <a class="uk-modal-close uk-close"></a>
        <p>Lorem ipsum...</p>
    </div>
</div>

Your jQuery code should like :

$(document).ready(function(){

    $.UIkit.modal('#my-id').show();
    $.UIkit.modal('#my-id2').show();  

});

This should work

like image 26
Bhavin Solanki Avatar answered Nov 01 '22 17:11

Bhavin Solanki