hopeless
hopeless

Reputation: 96

How should i handle calling modal widow from controller under certain conditions

I am trying to create a modal window that will open under some conditions. I did create a modal window that is opening on button click. What should i change?

My view:

<button type="button" data-toggle="modal" data-target="#popupModal">open</button>
    <div id="popupModal"
         class="modal hide fade"
         tabindex="-1"
         role="dialog"
         aria-labelledby="popupModalLabel"
         aria-hidden="true">


        ...some html
    </div>
</div>

my controller:

if (some conditions)
                    {
                        //here i want to open my modal window somehow
                    }

Upvotes: 0

Views: 48

Answers (2)

N.S
N.S

Reputation: 139

From your controller Send your option in data array when you load your view. for example, your code should be Something like this..

Controller:

$data = array();
if (some conditions)
{
    $data['option1'] = 'modal1';
}
else{
    $data['option2'] = 'modal2';
}
$this->load->view('your view file', $data);

View:

if($option1){
    // modal 1 html
}
else{
   // modal 2 html
}

Try this. i hope you get an idea.

Upvotes: 0

Mathiasfc
Mathiasfc

Reputation: 1697

You can check these conditions in the button click event,

$(button).click(function(){
     if (some conditions)
     {
         $("#popupModal").modal("show");
         //$("#popupModal").show();
     }
});

I've created jsFiddle with an example for you: JsFIddle

Upvotes: 1

Related Questions